<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>ElasticSearch 基础概念与入门使用 | 鱼皮的编程宝典</title>
    <meta name="generator" content="VuePress 1.9.10">
    <link rel="icon" href="/favicon.ico">
    <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?2675818a983a3131404cee835018f016";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
      </script>
    <meta name="description" content="贴心的编程学习路线，全面的编程知识百科">
    <meta property="article:modified_time" content="2023-12-26T05:17:29.000Z">
    <meta property="og:site_name" content="鱼皮的编程宝典">
    <meta property="og:title" content="ElasticSearch 基础概念与入门使用">
    <meta property="og:type" content="article">
    <meta property="og:url" content="https://codefather.cn/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/">
    <meta name="twitter:title" content="ElasticSearch 基础概念与入门使用">
    <meta name="twitter:url" content="https://codefather.cn/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:label1" content="Written by">
    <meta name="twitter:label2" content="Filed under">
    <meta name="twitter:data2" content="程序员, 编程, 计算机">
    <meta property="article:tag" content="程序员">
    <meta name="keywords" content="程序员鱼皮, 编程学习路线, 编程知识百科, Java, 编程导航, 前端, 开发, 编程分享, 项目, IT, 求职, 面经">
    
    <link rel="preload" href="/assets/css/0.styles.40c15e22.css" as="style"><link rel="preload" href="/assets/js/app.12ab4756.js" as="script"><link rel="preload" href="/assets/js/2.fd06b53e.js" as="script"><link rel="preload" href="/assets/js/51.bed7cf61.js" as="script"><link rel="prefetch" href="/assets/js/1.17ea1209.js"><link rel="prefetch" href="/assets/js/10.d9532d8f.js"><link rel="prefetch" href="/assets/js/100.064ea126.js"><link rel="prefetch" href="/assets/js/101.d64c5b33.js"><link rel="prefetch" href="/assets/js/102.5e29a62c.js"><link rel="prefetch" href="/assets/js/103.59ad6cd7.js"><link rel="prefetch" href="/assets/js/104.ae4763e8.js"><link rel="prefetch" href="/assets/js/105.2a9124be.js"><link rel="prefetch" href="/assets/js/106.529bca07.js"><link rel="prefetch" href="/assets/js/107.c8671a0d.js"><link rel="prefetch" href="/assets/js/108.55c93c64.js"><link rel="prefetch" href="/assets/js/109.7d1efa54.js"><link rel="prefetch" href="/assets/js/11.2f89b5eb.js"><link rel="prefetch" href="/assets/js/110.0caecbf5.js"><link rel="prefetch" href="/assets/js/111.a2aeae49.js"><link rel="prefetch" href="/assets/js/112.eb7ceda5.js"><link rel="prefetch" href="/assets/js/113.f304408d.js"><link rel="prefetch" href="/assets/js/114.988c637f.js"><link rel="prefetch" href="/assets/js/115.bfdeed31.js"><link rel="prefetch" href="/assets/js/116.a47b8c53.js"><link rel="prefetch" href="/assets/js/117.2e1e8250.js"><link rel="prefetch" href="/assets/js/118.758ce408.js"><link rel="prefetch" href="/assets/js/119.73d9e688.js"><link rel="prefetch" href="/assets/js/12.53aaa509.js"><link rel="prefetch" href="/assets/js/120.202a8b2e.js"><link rel="prefetch" href="/assets/js/121.ca91d59a.js"><link rel="prefetch" href="/assets/js/122.8804c0dd.js"><link rel="prefetch" href="/assets/js/123.ceada225.js"><link rel="prefetch" href="/assets/js/124.4b2718b7.js"><link rel="prefetch" href="/assets/js/125.72134235.js"><link rel="prefetch" href="/assets/js/126.167b162c.js"><link rel="prefetch" href="/assets/js/127.f8139c17.js"><link rel="prefetch" href="/assets/js/128.da64a377.js"><link rel="prefetch" href="/assets/js/129.c07963b1.js"><link rel="prefetch" href="/assets/js/13.52940164.js"><link rel="prefetch" href="/assets/js/130.f66fc8bb.js"><link rel="prefetch" href="/assets/js/131.a913c7dd.js"><link rel="prefetch" href="/assets/js/132.ea648654.js"><link rel="prefetch" href="/assets/js/133.074ca70e.js"><link rel="prefetch" href="/assets/js/134.dc79ddd8.js"><link rel="prefetch" href="/assets/js/135.c4516208.js"><link rel="prefetch" href="/assets/js/136.2546baf7.js"><link rel="prefetch" href="/assets/js/137.56454fc6.js"><link rel="prefetch" href="/assets/js/138.bdb002bf.js"><link rel="prefetch" href="/assets/js/139.40a2f9b5.js"><link rel="prefetch" href="/assets/js/14.ade1e74d.js"><link rel="prefetch" href="/assets/js/140.06b20427.js"><link rel="prefetch" href="/assets/js/141.8dd992e3.js"><link rel="prefetch" href="/assets/js/142.d9305485.js"><link rel="prefetch" href="/assets/js/143.41bf907e.js"><link rel="prefetch" href="/assets/js/144.c138960c.js"><link rel="prefetch" href="/assets/js/145.fc5b38c8.js"><link rel="prefetch" href="/assets/js/146.c9166b70.js"><link rel="prefetch" href="/assets/js/147.c31d8a01.js"><link rel="prefetch" href="/assets/js/148.5c0534ca.js"><link rel="prefetch" href="/assets/js/149.d2355ea2.js"><link rel="prefetch" href="/assets/js/15.970a8ca5.js"><link rel="prefetch" href="/assets/js/150.c1644898.js"><link rel="prefetch" href="/assets/js/151.b6e4adf0.js"><link rel="prefetch" href="/assets/js/152.7a5071aa.js"><link rel="prefetch" href="/assets/js/153.31abbc68.js"><link rel="prefetch" href="/assets/js/154.9c6bb079.js"><link rel="prefetch" href="/assets/js/155.e5506a40.js"><link rel="prefetch" href="/assets/js/156.992dab50.js"><link rel="prefetch" href="/assets/js/157.12a6ee84.js"><link rel="prefetch" href="/assets/js/158.84dc1045.js"><link rel="prefetch" href="/assets/js/159.fd2022b1.js"><link rel="prefetch" href="/assets/js/16.ff971500.js"><link rel="prefetch" href="/assets/js/160.8d8889cd.js"><link rel="prefetch" href="/assets/js/161.31797def.js"><link rel="prefetch" href="/assets/js/162.bfae7a75.js"><link rel="prefetch" href="/assets/js/163.e5e8094d.js"><link rel="prefetch" href="/assets/js/164.870f212c.js"><link rel="prefetch" href="/assets/js/165.8da20a31.js"><link rel="prefetch" href="/assets/js/166.950a187d.js"><link rel="prefetch" href="/assets/js/167.fd042c52.js"><link rel="prefetch" href="/assets/js/168.7d9f058d.js"><link rel="prefetch" href="/assets/js/169.205df80e.js"><link rel="prefetch" href="/assets/js/17.4b045b26.js"><link rel="prefetch" href="/assets/js/170.270108a3.js"><link rel="prefetch" href="/assets/js/171.9f03d27d.js"><link rel="prefetch" href="/assets/js/172.1882bac7.js"><link rel="prefetch" href="/assets/js/173.fc1fe7d4.js"><link rel="prefetch" href="/assets/js/174.d77c927b.js"><link rel="prefetch" href="/assets/js/175.019b9e83.js"><link rel="prefetch" href="/assets/js/176.5ce31bd8.js"><link rel="prefetch" href="/assets/js/177.9a2006f2.js"><link rel="prefetch" href="/assets/js/178.88265ac1.js"><link rel="prefetch" href="/assets/js/179.3205ce07.js"><link rel="prefetch" href="/assets/js/18.1cdd0514.js"><link rel="prefetch" href="/assets/js/180.2ff51f44.js"><link rel="prefetch" href="/assets/js/181.f792ce97.js"><link rel="prefetch" href="/assets/js/182.103328e1.js"><link rel="prefetch" href="/assets/js/183.40fde303.js"><link rel="prefetch" href="/assets/js/184.1f36ac78.js"><link rel="prefetch" href="/assets/js/185.cf3b1c00.js"><link rel="prefetch" href="/assets/js/186.f7981399.js"><link rel="prefetch" href="/assets/js/187.20fe296d.js"><link rel="prefetch" href="/assets/js/188.7b004fea.js"><link rel="prefetch" href="/assets/js/189.599ca2d9.js"><link rel="prefetch" href="/assets/js/19.5740e4d6.js"><link rel="prefetch" href="/assets/js/190.14087c07.js"><link rel="prefetch" href="/assets/js/191.b0f73f6d.js"><link rel="prefetch" href="/assets/js/192.9d171669.js"><link rel="prefetch" href="/assets/js/193.00975585.js"><link rel="prefetch" href="/assets/js/194.2c7c43b4.js"><link rel="prefetch" href="/assets/js/195.ff126254.js"><link rel="prefetch" href="/assets/js/196.6546ae1c.js"><link rel="prefetch" href="/assets/js/197.eedb67bb.js"><link rel="prefetch" href="/assets/js/198.acdcc22c.js"><link rel="prefetch" href="/assets/js/199.7993a6b2.js"><link rel="prefetch" href="/assets/js/20.8885a4fa.js"><link rel="prefetch" href="/assets/js/200.52f08765.js"><link rel="prefetch" href="/assets/js/201.b85ab10b.js"><link rel="prefetch" href="/assets/js/202.ccec1c85.js"><link rel="prefetch" href="/assets/js/203.3f50a6ed.js"><link rel="prefetch" href="/assets/js/204.f28b803b.js"><link rel="prefetch" href="/assets/js/205.c51c53fd.js"><link rel="prefetch" href="/assets/js/206.ba0aa8f6.js"><link rel="prefetch" href="/assets/js/207.0dce311a.js"><link rel="prefetch" href="/assets/js/208.0ea629a6.js"><link rel="prefetch" href="/assets/js/209.f48c3e71.js"><link rel="prefetch" href="/assets/js/21.0bb62db4.js"><link rel="prefetch" href="/assets/js/210.689db8f2.js"><link rel="prefetch" href="/assets/js/211.72bc0f1f.js"><link rel="prefetch" href="/assets/js/212.456135bd.js"><link rel="prefetch" href="/assets/js/213.d0ea50fc.js"><link rel="prefetch" href="/assets/js/214.1400da91.js"><link rel="prefetch" href="/assets/js/215.aeef3e5d.js"><link rel="prefetch" href="/assets/js/216.a60215af.js"><link rel="prefetch" href="/assets/js/217.d6cd8b69.js"><link rel="prefetch" href="/assets/js/218.1bd500fc.js"><link rel="prefetch" href="/assets/js/219.20faf611.js"><link rel="prefetch" href="/assets/js/22.3e8347a6.js"><link rel="prefetch" href="/assets/js/220.6714179b.js"><link rel="prefetch" href="/assets/js/221.fb5b643d.js"><link rel="prefetch" href="/assets/js/222.d96272e5.js"><link rel="prefetch" href="/assets/js/223.4cb7dc3d.js"><link rel="prefetch" href="/assets/js/224.500d94cc.js"><link rel="prefetch" href="/assets/js/225.d006c34e.js"><link rel="prefetch" href="/assets/js/226.73612150.js"><link rel="prefetch" href="/assets/js/227.b02db9d1.js"><link rel="prefetch" href="/assets/js/228.aad43ff2.js"><link rel="prefetch" href="/assets/js/229.65340802.js"><link rel="prefetch" href="/assets/js/23.ceb5a5ff.js"><link rel="prefetch" href="/assets/js/230.97cab104.js"><link rel="prefetch" href="/assets/js/231.8415349a.js"><link rel="prefetch" href="/assets/js/232.db6d2697.js"><link rel="prefetch" href="/assets/js/233.723d05b1.js"><link rel="prefetch" href="/assets/js/234.26ed5e94.js"><link rel="prefetch" href="/assets/js/235.a586122b.js"><link rel="prefetch" href="/assets/js/236.f802bda8.js"><link rel="prefetch" href="/assets/js/237.cc8767ad.js"><link rel="prefetch" href="/assets/js/238.6485459e.js"><link rel="prefetch" href="/assets/js/239.9fbf3a55.js"><link rel="prefetch" href="/assets/js/24.07267ac6.js"><link rel="prefetch" href="/assets/js/240.1188f244.js"><link rel="prefetch" href="/assets/js/241.cbfb154d.js"><link rel="prefetch" href="/assets/js/242.352cea5a.js"><link rel="prefetch" href="/assets/js/243.07947e1c.js"><link rel="prefetch" href="/assets/js/244.f5b26fa9.js"><link rel="prefetch" href="/assets/js/245.c6030e32.js"><link rel="prefetch" href="/assets/js/246.d3fe99f7.js"><link rel="prefetch" href="/assets/js/247.185ae95d.js"><link rel="prefetch" href="/assets/js/248.a5f1548c.js"><link rel="prefetch" href="/assets/js/249.19691113.js"><link rel="prefetch" href="/assets/js/25.15e1f641.js"><link rel="prefetch" href="/assets/js/250.72fa1d33.js"><link rel="prefetch" href="/assets/js/251.bedd56f7.js"><link rel="prefetch" href="/assets/js/252.32bbcc8b.js"><link rel="prefetch" href="/assets/js/253.b59e5846.js"><link rel="prefetch" href="/assets/js/254.c0e37e1a.js"><link rel="prefetch" href="/assets/js/255.850da3cc.js"><link rel="prefetch" href="/assets/js/256.952d9817.js"><link rel="prefetch" href="/assets/js/257.88667bb8.js"><link rel="prefetch" href="/assets/js/258.c5873c28.js"><link rel="prefetch" href="/assets/js/259.6ae1dcbc.js"><link rel="prefetch" href="/assets/js/26.35b2bbdc.js"><link rel="prefetch" href="/assets/js/260.cb940cc3.js"><link rel="prefetch" href="/assets/js/261.0686c3e9.js"><link rel="prefetch" href="/assets/js/262.d0719839.js"><link rel="prefetch" href="/assets/js/263.ae83ebc1.js"><link rel="prefetch" href="/assets/js/264.209ad8a3.js"><link rel="prefetch" href="/assets/js/265.be8d1ee8.js"><link rel="prefetch" href="/assets/js/266.c51bceaa.js"><link rel="prefetch" href="/assets/js/267.fe8af48a.js"><link rel="prefetch" href="/assets/js/268.e18ed861.js"><link rel="prefetch" href="/assets/js/269.7126031e.js"><link rel="prefetch" href="/assets/js/27.270fcb06.js"><link rel="prefetch" href="/assets/js/270.89ead106.js"><link rel="prefetch" href="/assets/js/271.0643d07a.js"><link rel="prefetch" href="/assets/js/272.32a8e4b0.js"><link rel="prefetch" href="/assets/js/273.9881da47.js"><link rel="prefetch" href="/assets/js/274.2de022ea.js"><link rel="prefetch" href="/assets/js/275.d9a4fe99.js"><link rel="prefetch" href="/assets/js/276.d33de2e9.js"><link rel="prefetch" href="/assets/js/277.1ec367ab.js"><link rel="prefetch" href="/assets/js/278.66ab7c11.js"><link rel="prefetch" href="/assets/js/279.ff51cd15.js"><link rel="prefetch" href="/assets/js/28.ef3f6db2.js"><link rel="prefetch" href="/assets/js/280.ef45ed5f.js"><link rel="prefetch" href="/assets/js/281.87f26b81.js"><link rel="prefetch" href="/assets/js/282.c8ef594b.js"><link rel="prefetch" href="/assets/js/283.15643091.js"><link rel="prefetch" href="/assets/js/284.c4f25b2e.js"><link rel="prefetch" href="/assets/js/285.2d16e4b6.js"><link rel="prefetch" href="/assets/js/286.44eba266.js"><link rel="prefetch" href="/assets/js/287.7613e62f.js"><link rel="prefetch" href="/assets/js/288.b9546d55.js"><link rel="prefetch" href="/assets/js/289.125f85d8.js"><link rel="prefetch" href="/assets/js/29.177558be.js"><link rel="prefetch" href="/assets/js/290.db375797.js"><link rel="prefetch" href="/assets/js/291.90946626.js"><link rel="prefetch" href="/assets/js/292.a4524678.js"><link rel="prefetch" href="/assets/js/293.3ed9b083.js"><link rel="prefetch" href="/assets/js/294.d6c14116.js"><link rel="prefetch" href="/assets/js/295.2b485032.js"><link rel="prefetch" href="/assets/js/296.29d9aa0f.js"><link rel="prefetch" href="/assets/js/297.bfd72435.js"><link rel="prefetch" href="/assets/js/298.fc056989.js"><link rel="prefetch" href="/assets/js/299.0a3f258e.js"><link rel="prefetch" href="/assets/js/3.4dc033c7.js"><link rel="prefetch" href="/assets/js/30.248a229d.js"><link rel="prefetch" href="/assets/js/300.d064d776.js"><link rel="prefetch" href="/assets/js/301.d95b9fc0.js"><link rel="prefetch" href="/assets/js/302.1afa637a.js"><link rel="prefetch" href="/assets/js/303.231beaa8.js"><link rel="prefetch" href="/assets/js/304.05df35d9.js"><link rel="prefetch" href="/assets/js/305.f2d83cf9.js"><link rel="prefetch" href="/assets/js/306.d54f5e5e.js"><link rel="prefetch" href="/assets/js/307.d5df9000.js"><link rel="prefetch" href="/assets/js/308.ef2f52b3.js"><link rel="prefetch" href="/assets/js/309.d1f13319.js"><link rel="prefetch" href="/assets/js/31.32a62b91.js"><link rel="prefetch" href="/assets/js/310.30b84be3.js"><link rel="prefetch" href="/assets/js/311.d79e3145.js"><link rel="prefetch" href="/assets/js/312.58e24f19.js"><link rel="prefetch" href="/assets/js/313.9809a122.js"><link rel="prefetch" href="/assets/js/314.e92e41b1.js"><link rel="prefetch" href="/assets/js/315.8c2fc1d4.js"><link rel="prefetch" href="/assets/js/316.a0904343.js"><link rel="prefetch" href="/assets/js/317.18e42b54.js"><link rel="prefetch" href="/assets/js/318.6b051d27.js"><link rel="prefetch" href="/assets/js/319.513b0197.js"><link rel="prefetch" href="/assets/js/32.23b75afc.js"><link rel="prefetch" href="/assets/js/320.ae91bc36.js"><link rel="prefetch" href="/assets/js/321.a194efea.js"><link rel="prefetch" href="/assets/js/322.8273020e.js"><link rel="prefetch" href="/assets/js/323.d332e08f.js"><link rel="prefetch" href="/assets/js/324.ed867b64.js"><link rel="prefetch" href="/assets/js/325.c43ccf9a.js"><link rel="prefetch" href="/assets/js/326.9497d879.js"><link rel="prefetch" href="/assets/js/327.7f095e40.js"><link rel="prefetch" href="/assets/js/328.cb5c5847.js"><link rel="prefetch" href="/assets/js/329.d36b59f3.js"><link rel="prefetch" href="/assets/js/33.b258b779.js"><link rel="prefetch" href="/assets/js/330.b1a092b9.js"><link rel="prefetch" href="/assets/js/331.ff86566f.js"><link rel="prefetch" href="/assets/js/332.0daafa9f.js"><link rel="prefetch" href="/assets/js/333.b7e50524.js"><link rel="prefetch" href="/assets/js/334.7dcf9f0b.js"><link rel="prefetch" href="/assets/js/335.862c410a.js"><link rel="prefetch" href="/assets/js/336.c6384990.js"><link rel="prefetch" href="/assets/js/337.ab9d5e52.js"><link rel="prefetch" href="/assets/js/338.598ae59e.js"><link rel="prefetch" href="/assets/js/339.9b810ff8.js"><link rel="prefetch" href="/assets/js/34.3bd60f1f.js"><link rel="prefetch" href="/assets/js/340.5609a53c.js"><link rel="prefetch" href="/assets/js/341.969d335a.js"><link rel="prefetch" href="/assets/js/342.43f85dba.js"><link rel="prefetch" href="/assets/js/343.47280ef9.js"><link rel="prefetch" href="/assets/js/344.346ae5fc.js"><link rel="prefetch" href="/assets/js/345.32166361.js"><link rel="prefetch" href="/assets/js/346.86ff128b.js"><link rel="prefetch" href="/assets/js/347.3c5421fe.js"><link rel="prefetch" href="/assets/js/348.95910300.js"><link rel="prefetch" href="/assets/js/349.004158d8.js"><link rel="prefetch" href="/assets/js/35.18e8f66a.js"><link rel="prefetch" href="/assets/js/350.e10b195b.js"><link rel="prefetch" href="/assets/js/351.12f89875.js"><link rel="prefetch" href="/assets/js/352.83957394.js"><link rel="prefetch" href="/assets/js/353.475971b9.js"><link rel="prefetch" href="/assets/js/354.8af7b26b.js"><link rel="prefetch" href="/assets/js/355.85925e24.js"><link rel="prefetch" href="/assets/js/356.1d77cf9c.js"><link rel="prefetch" href="/assets/js/357.b467d481.js"><link rel="prefetch" href="/assets/js/358.ac96f32d.js"><link rel="prefetch" href="/assets/js/359.e048bd10.js"><link rel="prefetch" href="/assets/js/36.a7ae257c.js"><link rel="prefetch" href="/assets/js/360.e9b45545.js"><link rel="prefetch" href="/assets/js/361.ad1bb45b.js"><link rel="prefetch" href="/assets/js/362.4e24a30b.js"><link rel="prefetch" href="/assets/js/363.64f7dad5.js"><link rel="prefetch" href="/assets/js/364.d9e3ebc2.js"><link rel="prefetch" href="/assets/js/365.330e3086.js"><link rel="prefetch" href="/assets/js/366.a6c0afb3.js"><link rel="prefetch" href="/assets/js/367.ffcefa40.js"><link rel="prefetch" href="/assets/js/368.664c8e4d.js"><link rel="prefetch" href="/assets/js/369.67da2dd2.js"><link rel="prefetch" href="/assets/js/37.d709f9a9.js"><link rel="prefetch" href="/assets/js/370.b1791970.js"><link rel="prefetch" href="/assets/js/371.743a461a.js"><link rel="prefetch" href="/assets/js/372.7703ef1b.js"><link rel="prefetch" href="/assets/js/373.17de31f6.js"><link rel="prefetch" href="/assets/js/374.e508be9e.js"><link rel="prefetch" href="/assets/js/375.6e2e9fe3.js"><link rel="prefetch" href="/assets/js/376.8ca3511a.js"><link rel="prefetch" href="/assets/js/377.bfcee39c.js"><link rel="prefetch" href="/assets/js/378.21852b78.js"><link rel="prefetch" href="/assets/js/379.9649c307.js"><link rel="prefetch" href="/assets/js/38.68ca920e.js"><link rel="prefetch" href="/assets/js/380.dadb4418.js"><link rel="prefetch" href="/assets/js/381.a03c993d.js"><link rel="prefetch" href="/assets/js/382.bb7c22c1.js"><link rel="prefetch" href="/assets/js/383.bd68b2e5.js"><link rel="prefetch" href="/assets/js/384.f6dc7457.js"><link rel="prefetch" href="/assets/js/385.14287a91.js"><link rel="prefetch" href="/assets/js/386.a6284ac2.js"><link rel="prefetch" href="/assets/js/387.c51f147a.js"><link rel="prefetch" href="/assets/js/388.06d9651e.js"><link rel="prefetch" href="/assets/js/389.2d85d927.js"><link rel="prefetch" href="/assets/js/39.de850db9.js"><link rel="prefetch" href="/assets/js/390.2397b3e0.js"><link rel="prefetch" href="/assets/js/391.8413aaaf.js"><link rel="prefetch" href="/assets/js/392.00eecaa4.js"><link rel="prefetch" href="/assets/js/393.351dd3fd.js"><link rel="prefetch" href="/assets/js/394.d2cc4a70.js"><link rel="prefetch" href="/assets/js/395.abee64bf.js"><link rel="prefetch" href="/assets/js/396.bc265e6a.js"><link rel="prefetch" href="/assets/js/397.e4a96944.js"><link rel="prefetch" href="/assets/js/398.f0d26b29.js"><link rel="prefetch" href="/assets/js/399.e77c3ddc.js"><link rel="prefetch" href="/assets/js/4.2f502b73.js"><link rel="prefetch" href="/assets/js/40.91635261.js"><link rel="prefetch" href="/assets/js/400.c7eac401.js"><link rel="prefetch" href="/assets/js/401.06092d16.js"><link rel="prefetch" href="/assets/js/402.4e08e496.js"><link rel="prefetch" href="/assets/js/403.deba4c77.js"><link rel="prefetch" href="/assets/js/404.9100e4df.js"><link rel="prefetch" href="/assets/js/405.e9f451e2.js"><link rel="prefetch" href="/assets/js/406.a0da4aa4.js"><link rel="prefetch" href="/assets/js/407.58b2b123.js"><link rel="prefetch" href="/assets/js/408.eb2cde2d.js"><link rel="prefetch" href="/assets/js/409.9041f749.js"><link rel="prefetch" href="/assets/js/41.169a3cfc.js"><link rel="prefetch" href="/assets/js/410.c12f3710.js"><link rel="prefetch" href="/assets/js/411.452cda45.js"><link rel="prefetch" href="/assets/js/412.8691317a.js"><link rel="prefetch" href="/assets/js/413.25a68f21.js"><link rel="prefetch" href="/assets/js/414.7a9699d8.js"><link rel="prefetch" href="/assets/js/415.6e8cdaff.js"><link rel="prefetch" href="/assets/js/416.e8a86529.js"><link rel="prefetch" href="/assets/js/417.28330bde.js"><link rel="prefetch" href="/assets/js/418.2fed8e17.js"><link rel="prefetch" href="/assets/js/419.773032f4.js"><link rel="prefetch" href="/assets/js/42.e17cd061.js"><link rel="prefetch" href="/assets/js/420.56681228.js"><link rel="prefetch" href="/assets/js/421.0d170e13.js"><link rel="prefetch" href="/assets/js/422.fc8c2a11.js"><link rel="prefetch" href="/assets/js/423.e34ea6a6.js"><link rel="prefetch" href="/assets/js/424.20fe8748.js"><link rel="prefetch" href="/assets/js/425.f001b7cd.js"><link rel="prefetch" href="/assets/js/426.a91230ef.js"><link rel="prefetch" href="/assets/js/427.c6c9fe8d.js"><link rel="prefetch" href="/assets/js/428.9d4f5e41.js"><link rel="prefetch" href="/assets/js/429.c81cfd3f.js"><link rel="prefetch" href="/assets/js/43.f88aa667.js"><link rel="prefetch" href="/assets/js/430.eb61372f.js"><link rel="prefetch" href="/assets/js/431.4a25365a.js"><link rel="prefetch" href="/assets/js/432.42fc1bbe.js"><link rel="prefetch" href="/assets/js/433.8e9ac9f0.js"><link rel="prefetch" href="/assets/js/434.fdd0b160.js"><link rel="prefetch" href="/assets/js/435.d6cbac31.js"><link rel="prefetch" href="/assets/js/436.17750ba2.js"><link rel="prefetch" href="/assets/js/437.a1468099.js"><link rel="prefetch" href="/assets/js/438.ac6a45c2.js"><link rel="prefetch" href="/assets/js/439.242ae27a.js"><link rel="prefetch" href="/assets/js/44.3f36e228.js"><link rel="prefetch" href="/assets/js/440.b80b520c.js"><link rel="prefetch" href="/assets/js/441.e51a4bbb.js"><link rel="prefetch" href="/assets/js/442.ab0b3eda.js"><link rel="prefetch" href="/assets/js/443.47e44250.js"><link rel="prefetch" href="/assets/js/444.54c3b425.js"><link rel="prefetch" href="/assets/js/445.e006c12e.js"><link rel="prefetch" href="/assets/js/446.f2b79730.js"><link rel="prefetch" href="/assets/js/447.2509a397.js"><link rel="prefetch" href="/assets/js/448.b7d69dfc.js"><link rel="prefetch" href="/assets/js/449.8a575d9b.js"><link rel="prefetch" href="/assets/js/45.be1455b1.js"><link rel="prefetch" href="/assets/js/450.ad421aeb.js"><link rel="prefetch" href="/assets/js/451.f09912ae.js"><link rel="prefetch" href="/assets/js/452.f528c4ce.js"><link rel="prefetch" href="/assets/js/453.fc4dc0f9.js"><link rel="prefetch" href="/assets/js/454.733c315c.js"><link rel="prefetch" href="/assets/js/455.44fe35b1.js"><link rel="prefetch" href="/assets/js/456.7f650035.js"><link rel="prefetch" href="/assets/js/457.77ebc183.js"><link rel="prefetch" href="/assets/js/458.133078f4.js"><link rel="prefetch" href="/assets/js/459.33728b5e.js"><link rel="prefetch" href="/assets/js/46.5ad74cb5.js"><link rel="prefetch" href="/assets/js/460.6946f564.js"><link rel="prefetch" href="/assets/js/461.6f906c5c.js"><link rel="prefetch" href="/assets/js/462.26eca27e.js"><link rel="prefetch" href="/assets/js/463.e02e5f65.js"><link rel="prefetch" href="/assets/js/464.0df25c63.js"><link rel="prefetch" href="/assets/js/465.80cd249e.js"><link rel="prefetch" href="/assets/js/466.a0921e86.js"><link rel="prefetch" href="/assets/js/467.1bec2b47.js"><link rel="prefetch" href="/assets/js/468.b6fa37c1.js"><link rel="prefetch" href="/assets/js/469.a1d2487e.js"><link rel="prefetch" href="/assets/js/47.03df5d0a.js"><link rel="prefetch" href="/assets/js/470.36a4b9c8.js"><link rel="prefetch" href="/assets/js/471.28895273.js"><link rel="prefetch" href="/assets/js/472.b9fe392f.js"><link rel="prefetch" href="/assets/js/473.a2835d9c.js"><link rel="prefetch" href="/assets/js/474.cd57b37d.js"><link rel="prefetch" href="/assets/js/475.8d5a9792.js"><link rel="prefetch" href="/assets/js/476.f7f3781c.js"><link rel="prefetch" href="/assets/js/477.9b710b04.js"><link rel="prefetch" href="/assets/js/478.46d66687.js"><link rel="prefetch" href="/assets/js/479.e7444705.js"><link rel="prefetch" href="/assets/js/48.48f286ba.js"><link rel="prefetch" href="/assets/js/480.da2b750a.js"><link rel="prefetch" href="/assets/js/481.838a8e04.js"><link rel="prefetch" href="/assets/js/482.02bf8041.js"><link rel="prefetch" href="/assets/js/483.bb29ef2f.js"><link rel="prefetch" href="/assets/js/484.aebb68bd.js"><link rel="prefetch" href="/assets/js/485.a66ab41b.js"><link rel="prefetch" href="/assets/js/486.8df516fb.js"><link rel="prefetch" href="/assets/js/487.86d28130.js"><link rel="prefetch" href="/assets/js/488.0863da70.js"><link rel="prefetch" href="/assets/js/489.5d4d9e88.js"><link rel="prefetch" href="/assets/js/49.1ca52d11.js"><link rel="prefetch" href="/assets/js/490.3fd65d85.js"><link rel="prefetch" href="/assets/js/491.ae3a2f87.js"><link rel="prefetch" href="/assets/js/492.6f54679b.js"><link rel="prefetch" href="/assets/js/493.a594b1f4.js"><link rel="prefetch" href="/assets/js/494.4f03fae1.js"><link rel="prefetch" href="/assets/js/495.ae50b66b.js"><link rel="prefetch" href="/assets/js/496.bc92d835.js"><link rel="prefetch" href="/assets/js/497.eac65251.js"><link rel="prefetch" href="/assets/js/498.1d726726.js"><link rel="prefetch" href="/assets/js/499.01e4f7d1.js"><link rel="prefetch" href="/assets/js/5.7b1f056c.js"><link rel="prefetch" href="/assets/js/50.73732fe2.js"><link rel="prefetch" href="/assets/js/500.062ade4e.js"><link rel="prefetch" href="/assets/js/501.e6a711dc.js"><link rel="prefetch" href="/assets/js/502.c79e28e2.js"><link rel="prefetch" href="/assets/js/503.bf97bce9.js"><link rel="prefetch" href="/assets/js/504.b2784ef0.js"><link rel="prefetch" href="/assets/js/505.0767ba54.js"><link rel="prefetch" href="/assets/js/506.8ae14637.js"><link rel="prefetch" href="/assets/js/507.003e2349.js"><link rel="prefetch" href="/assets/js/508.ecb5e6bd.js"><link rel="prefetch" href="/assets/js/509.b644f44a.js"><link rel="prefetch" href="/assets/js/510.b660946f.js"><link rel="prefetch" href="/assets/js/511.cb186c8f.js"><link rel="prefetch" href="/assets/js/512.d176170f.js"><link rel="prefetch" href="/assets/js/513.18a1afa5.js"><link rel="prefetch" href="/assets/js/514.4a33e931.js"><link rel="prefetch" href="/assets/js/515.8496bd4d.js"><link rel="prefetch" href="/assets/js/516.529b9476.js"><link rel="prefetch" href="/assets/js/517.289738f1.js"><link rel="prefetch" href="/assets/js/518.eda39556.js"><link rel="prefetch" href="/assets/js/519.85b42de5.js"><link rel="prefetch" href="/assets/js/52.22a7da62.js"><link rel="prefetch" href="/assets/js/520.8b531775.js"><link rel="prefetch" href="/assets/js/521.8e4b66fb.js"><link rel="prefetch" href="/assets/js/522.050bfc55.js"><link rel="prefetch" href="/assets/js/523.e973f1e0.js"><link rel="prefetch" href="/assets/js/524.fd160738.js"><link rel="prefetch" href="/assets/js/525.5a4bc307.js"><link rel="prefetch" href="/assets/js/526.361bc4fa.js"><link rel="prefetch" href="/assets/js/527.06ee9d73.js"><link rel="prefetch" href="/assets/js/528.22d9b118.js"><link rel="prefetch" href="/assets/js/529.b7592c16.js"><link rel="prefetch" href="/assets/js/53.767f3bbf.js"><link rel="prefetch" href="/assets/js/530.ad96d564.js"><link rel="prefetch" href="/assets/js/531.61905243.js"><link rel="prefetch" href="/assets/js/532.11aebf61.js"><link rel="prefetch" href="/assets/js/533.0cddb226.js"><link rel="prefetch" href="/assets/js/534.d1c9cc36.js"><link rel="prefetch" href="/assets/js/54.d1f9eec8.js"><link rel="prefetch" href="/assets/js/55.aa90e812.js"><link rel="prefetch" href="/assets/js/56.4d7f81f2.js"><link rel="prefetch" href="/assets/js/57.3c540e8d.js"><link rel="prefetch" href="/assets/js/58.fc1c23f2.js"><link rel="prefetch" href="/assets/js/59.c7a7a4c0.js"><link rel="prefetch" href="/assets/js/6.056886f1.js"><link rel="prefetch" href="/assets/js/60.40e590ae.js"><link rel="prefetch" href="/assets/js/61.e400b323.js"><link rel="prefetch" href="/assets/js/62.bbb30ef1.js"><link rel="prefetch" href="/assets/js/63.c31cd2bb.js"><link rel="prefetch" href="/assets/js/64.62321188.js"><link rel="prefetch" href="/assets/js/65.44adc2b3.js"><link rel="prefetch" href="/assets/js/66.b5740d4f.js"><link rel="prefetch" href="/assets/js/67.76c3624c.js"><link rel="prefetch" href="/assets/js/68.6dd982d4.js"><link rel="prefetch" href="/assets/js/69.eb1390ec.js"><link rel="prefetch" href="/assets/js/7.a96cecf9.js"><link rel="prefetch" href="/assets/js/70.8c882bdd.js"><link rel="prefetch" href="/assets/js/71.001c968a.js"><link rel="prefetch" href="/assets/js/72.ae4ca075.js"><link rel="prefetch" href="/assets/js/73.d6ae6a27.js"><link rel="prefetch" href="/assets/js/74.fba60e37.js"><link rel="prefetch" href="/assets/js/75.0b1bf7bf.js"><link rel="prefetch" href="/assets/js/76.ee19d90e.js"><link rel="prefetch" href="/assets/js/77.fe8ac5f0.js"><link rel="prefetch" href="/assets/js/78.ae09432e.js"><link rel="prefetch" href="/assets/js/79.c1b10e2d.js"><link rel="prefetch" href="/assets/js/80.ae809538.js"><link rel="prefetch" href="/assets/js/81.ca11b4c7.js"><link rel="prefetch" href="/assets/js/82.308b98e4.js"><link rel="prefetch" href="/assets/js/83.355d9dde.js"><link rel="prefetch" href="/assets/js/84.a2b61d48.js"><link rel="prefetch" href="/assets/js/85.cf992fda.js"><link rel="prefetch" href="/assets/js/86.f547c7ea.js"><link rel="prefetch" href="/assets/js/87.2b02746a.js"><link rel="prefetch" href="/assets/js/88.e939aad5.js"><link rel="prefetch" href="/assets/js/89.b000c42a.js"><link rel="prefetch" href="/assets/js/90.dadef001.js"><link rel="prefetch" href="/assets/js/91.c0fe2e32.js"><link rel="prefetch" href="/assets/js/92.e09650b9.js"><link rel="prefetch" href="/assets/js/93.427c7280.js"><link rel="prefetch" href="/assets/js/94.90fc5f58.js"><link rel="prefetch" href="/assets/js/95.13d42b3a.js"><link rel="prefetch" href="/assets/js/96.d0a2ea8c.js"><link rel="prefetch" href="/assets/js/97.cc9a0eda.js"><link rel="prefetch" href="/assets/js/98.3c9f1b7e.js"><link rel="prefetch" href="/assets/js/99.0420dcbc.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.33b2b47d.js">
    <link rel="stylesheet" href="/assets/css/0.styles.40c15e22.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="鱼皮的编程宝典" class="logo"> <span class="site-name can-hide">鱼皮的编程宝典</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/学习路线/" class="nav-link">
  学习路线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="自学之路" class="dropdown-title"><span class="title">自学之路</span> <span class="arrow down"></span></button> <button type="button" aria-label="自学之路" class="mobile-dropdown-title"><span class="title">自学之路</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/自学之路/#大学经历" class="nav-link">
  大学经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#求职经历" class="nav-link">
  求职经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#职场工作" class="nav-link">
  职场工作
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#创作经历" class="nav-link">
  创作经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#创业经历" class="nav-link">
  创业经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#生活日常" class="nav-link">
  生活日常
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="编程分享" class="dropdown-title"><span class="title">编程分享</span> <span class="arrow down"></span></button> <button type="button" aria-label="编程分享" class="mobile-dropdown-title"><span class="title">编程分享</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/编程分享/#入门必看-学习路线" class="nav-link">
  入门必看-学习路线
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#学习指南" class="nav-link">
  学习指南
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#开发经验" class="nav-link">
  开发经验
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#求职经验" class="nav-link">
  求职经验
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#职场经验" class="nav-link">
  职场经验
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#技术分享" class="nav-link">
  技术分享
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#实战教程" class="nav-link">
  实战教程
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#其他" class="nav-link">
  其他
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#📚-项目教程" class="nav-link">
  项目教程
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#个人作品" class="nav-link">
  个人作品
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#🎁-编程资源" class="nav-link">
  编程资源
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#🌐-科技科普" class="nav-link">
  科技科普
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow down"></span></button> <button type="button" aria-label="项目实战" class="mobile-dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/项目实战/OJ 判题系统.html" class="nav-link">
  OJ 判题系统
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/智能 BI 平台.html" class="nav-link">
  智能 BI 平台
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/聚合搜索平台.html" class="nav-link">
  聚合搜索平台
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/API 开放平台.html" class="nav-link">
  API 开放平台
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/伙伴匹配系统.html" class="nav-link">
  伙伴匹配系统
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/用户中心项目.html" class="nav-link">
  用户中心项目
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/Java 后端万用项目模板.html" class="nav-link">
  Java 后端万用项目模板
</a></li></ul></div></div><div class="nav-item"><a href="/知识碎片/" class="nav-link">
  知识碎片
</a></div><div class="nav-item"><a href="/编程导航/" class="nav-link">
  🔥 编程导航
</a></div><div class="nav-item"><a href="/产品服务/" class="nav-link">
  产品服务
</a></div><div class="nav-item"><a href="/作者/" class="nav-link">
  作者
</a></div> <a href="https://github.com/liyupi/codefather" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/学习路线/" class="nav-link">
  学习路线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="自学之路" class="dropdown-title"><span class="title">自学之路</span> <span class="arrow down"></span></button> <button type="button" aria-label="自学之路" class="mobile-dropdown-title"><span class="title">自学之路</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/自学之路/#大学经历" class="nav-link">
  大学经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#求职经历" class="nav-link">
  求职经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#职场工作" class="nav-link">
  职场工作
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#创作经历" class="nav-link">
  创作经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#创业经历" class="nav-link">
  创业经历
</a></li><li class="dropdown-item"><!----> <a href="/自学之路/#生活日常" class="nav-link">
  生活日常
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="编程分享" class="dropdown-title"><span class="title">编程分享</span> <span class="arrow down"></span></button> <button type="button" aria-label="编程分享" class="mobile-dropdown-title"><span class="title">编程分享</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/编程分享/#入门必看-学习路线" class="nav-link">
  入门必看-学习路线
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#学习指南" class="nav-link">
  学习指南
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#开发经验" class="nav-link">
  开发经验
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#求职经验" class="nav-link">
  求职经验
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#职场经验" class="nav-link">
  职场经验
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#技术分享" class="nav-link">
  技术分享
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#实战教程" class="nav-link">
  实战教程
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#其他" class="nav-link">
  其他
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#📚-项目教程" class="nav-link">
  项目教程
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#个人作品" class="nav-link">
  个人作品
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#🎁-编程资源" class="nav-link">
  编程资源
</a></li><li class="dropdown-item"><!----> <a href="/编程分享/#🌐-科技科普" class="nav-link">
  科技科普
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow down"></span></button> <button type="button" aria-label="项目实战" class="mobile-dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/项目实战/OJ 判题系统.html" class="nav-link">
  OJ 判题系统
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/智能 BI 平台.html" class="nav-link">
  智能 BI 平台
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/聚合搜索平台.html" class="nav-link">
  聚合搜索平台
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/API 开放平台.html" class="nav-link">
  API 开放平台
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/伙伴匹配系统.html" class="nav-link">
  伙伴匹配系统
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/用户中心项目.html" class="nav-link">
  用户中心项目
</a></li><li class="dropdown-item"><!----> <a href="/项目实战/Java 后端万用项目模板.html" class="nav-link">
  Java 后端万用项目模板
</a></li></ul></div></div><div class="nav-item"><a href="/知识碎片/" class="nav-link">
  知识碎片
</a></div><div class="nav-item"><a href="/编程导航/" class="nav-link">
  🔥 编程导航
</a></div><div class="nav-item"><a href="/产品服务/" class="nav-link">
  产品服务
</a></div><div class="nav-item"><a href="/作者/" class="nav-link">
  作者
</a></div> <a href="https://github.com/liyupi/codefather" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><a href="/%E7%9F%A5%E8%AF%86%E7%A2%8E%E7%89%87/" class="sidebar-link">编程导航知识碎片</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>知识碎片</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/_4-%E7%A7%8D%E6%96%B9%E6%B3%95-%E5%BF%AB%E9%80%9F%E5%88%9D%E5%A7%8B%E5%8C%96-java-%E9%A1%B9%E7%9B%AE/" class="sidebar-link">4 种方法，快速初始化 Java 项目</a></li><li><a href="/%E4%BD%BF%E7%94%A8%E5%90%8E%E7%AB%AF%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E5%99%A8-%E6%8F%90%E9%AB%98%E5%BC%80%E5%8F%91%E6%95%88%E7%8E%87/" class="sidebar-link">使用后端代码生成器，提高开发效率</a></li><li><a href="/%E5%89%8D%E7%AB%AF%E5%BF%85%E5%AD%A6%E7%9A%84%E5%BC%80%E5%8F%91%E6%A1%86%E6%9E%B6-ant-design-pro/" class="sidebar-link">前端必学的开发框架，Ant Design Pro</a></li><li><a href="/%E5%90%8E%E7%AB%AF%E5%A6%82%E4%BD%95%E7%BC%96%E5%86%99%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" class="sidebar-link">后端如何编写单元测试？</a></li><li><a href="/%E5%90%8E%E7%AB%AF%E9%A1%B9%E7%9B%AE%E7%BB%8F%E5%85%B8%E5%88%86%E5%B1%82%E6%9E%B6%E6%9E%84%E4%BB%8B%E7%BB%8D/" class="sidebar-link">后端项目经典分层架构介绍</a></li><li><a href="/%E5%A6%82%E4%BD%95%E9%AB%98%E6%95%88%E6%B5%8B%E8%AF%95%E6%8E%A5%E5%8F%A3-%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/" class="sidebar-link">如何高效测试接口？自动生成接口文档</a></li><li><a href="/%E5%BC%80%E5%8F%91%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E7%BE%A4%E6%9C%BA%E5%99%A8%E4%BA%BA-%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E6%8F%90%E9%86%92/" class="sidebar-link">开发企业微信群机器人，实现定时提醒</a></li><li><a href="/%E5%A6%82%E4%BD%95%E8%A7%A3%E5%86%B3%E6%95%B0%E6%8D%AE%E6%9F%A5%E8%AF%A2%E4%B8%BA%E7%A9%BA%E7%9A%84-bug/" class="sidebar-link">如何解决数据查询为空的 Bug？</a></li><li><a href="/git-%E6%8F%90%E4%BA%A4%E7%AB%9F%E7%84%B6%E8%BF%98%E8%83%BD%E8%BF%99%E4%B9%88%E7%94%A8/" class="sidebar-link">Git 提交竟然还能这么用？</a></li><li><a href="/%E3%80%90%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E3%80%91%E8%A3%85%E9%A5%B0%E8%80%85%E6%A8%A1%E5%BC%8F-%E5%8F%8A%E5%85%B6%E5%9C%A8jdk%E6%BA%90%E7%A0%81%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/" class="sidebar-link">【设计模式】装饰者模式，及其在JDK源码中的应用</a></li><li><a href="/%E7%94%A8%E5%9B%9B%E7%A7%8D%E9%94%81%E5%AE%9E%E7%8E%B0%E5%8A%A0%E5%85%A5%E9%98%9F%E4%BC%8D%E5%8A%9F%E8%83%BD-%E4%BC%99%E4%BC%B4%E5%8C%B9%E9%85%8D%E7%B3%BB%E7%BB%9F/" class="sidebar-link">用四种锁实现加入队伍功能(伙伴匹配系统)</a></li><li><a href="/%E7%94%A8-validated%E6%B3%A8%E8%A7%A3%E5%AE%9E%E7%8E%B0%E9%9D%9E%E7%A9%BA%E6%A0%A1%E9%AA%8C/" class="sidebar-link">用@Validated注解实现非空校验</a></li><li><a href="/%E4%BD%BF%E7%94%A8%E7%AC%AC%E4%B8%89%E6%96%B9%E6%9C%8D%E5%8A%A1-%E5%AE%9D%E5%A1%94-%E5%BF%AB%E9%80%9F%E9%83%A8%E7%BD%B2%E9%A1%B9%E7%9B%AE/" class="sidebar-link">使用第三方服务（宝塔）快速部署项目</a></li><li><a href="/restful-%E6%8E%A5%E5%8F%A3%E5%AE%9E%E7%8E%B0%E4%B8%8E%E6%B5%8B%E8%AF%95-spring-boot/" class="sidebar-link">RESTful 接口实现与测试( Spring Boot )</a></li><li><a href="/%E5%BF%AB%E9%80%9F%E5%AD%A6%E4%BC%9A%E4%B8%BA%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%E5%81%9A%E8%B4%A1%E7%8C%AE/" class="sidebar-link">快速学会为开源项目做贡献</a></li><li><a href="/%E6%95%B4%E5%90%88spring-jdbc%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93/" class="sidebar-link">整合Spring JDBC操作数据库</a></li><li><a href="/maven-%E4%B8%AD%E5%A4%AE%E4%BB%93%E5%BA%93%E5%8F%91%E5%8C%85%E6%B5%81%E7%A8%8B/" class="sidebar-link">Maven 中央仓库发包流程</a></li><li><a href="/nacos-%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E6%90%AD%E5%BB%BA/" class="sidebar-link">Nacos 配置中心搭建</a></li><li><a href="/bean-%E6%8B%B7%E8%B4%9D%E4%B9%8B-mapstruct/" class="sidebar-link">Bean 拷贝之 MapStruct</a></li><li><a href="/%E4%BD%BF%E7%94%A8-freemarker-%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E%E7%94%9F%E6%88%90%E4%BB%A3%E7%A0%81/" class="sidebar-link">使用 FreeMarker 模板引擎生成代码</a></li><li><a href="/%E5%A6%82%E4%BD%95%E5%BF%AB%E9%80%9F%E5%BF%BD%E7%95%A5-git-%E6%96%87%E4%BB%B6%E6%8F%90%E4%BA%A4/" class="sidebar-link">如何快速忽略 Git 文件提交？</a></li><li><a href="/easyexcel-%E5%AF%BC%E5%87%BA%E6%96%87%E4%BB%B6/" class="sidebar-link">EasyExcel 导出文件</a></li><li><a href="/%E5%A6%82%E4%BD%95%E5%A4%84%E7%90%86-completablefuture-%E4%B8%AD%E7%9A%84%E4%B8%A4%E7%A7%8D%E5%BC%82%E5%B8%B8-%E6%99%BA%E8%83%BDbi%E9%A1%B9%E7%9B%AE/" class="sidebar-link">如何处理 CompletableFuture 中的两种异常(智能BI项目)</a></li><li><a href="/%E5%9F%BA%E4%BA%8E-session-%E5%AE%9E%E7%8E%B0%E7%9F%AD%E4%BF%A1%E7%99%BB%E5%BD%95/" class="sidebar-link">基于 Session 实现短信登录</a></li><li><a href="/synchronized-%E5%85%B3%E9%94%AE%E5%AD%97%E8%AF%A6%E8%A7%A3/" class="sidebar-link">Synchronized 关键字详解</a></li><li><a href="/redission-%E8%A7%A3%E9%94%81%E5%BC%82%E5%B8%B8%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/" class="sidebar-link">Redission 解锁异常解决方案</a></li><li><a href="/%E5%AE%9E%E7%8E%B0%E4%B8%BB%E9%A2%98%E6%8D%A2%E8%82%A4-css-%E5%8F%98%E9%87%8F-%E7%B1%BB%E5%90%8D%E5%88%87%E6%8D%A2/" class="sidebar-link">实现主题换肤( CSS 变量 + 类名切换)</a></li><li><a href="/springboot-%E6%95%B4%E5%90%88-minio%E5%85%A8%E6%B5%81%E7%A8%8B-%E4%BB%8E%E5%AE%89%E8%A3%85-minio-%E5%88%B0%E5%BA%94%E7%94%A8/" class="sidebar-link">SpringBoot 整合 Minio全流程（从安装 Minio 到应用）</a></li><li><a href="/%E3%80%90redis%E5%BA%94%E7%94%A8%E3%80%91uv%E7%BB%9F%E8%AE%A1/" class="sidebar-link">【Redis应用】UV统计</a></li><li><a href="/%E3%80%8A%E8%B4%AF%E7%A9%BF%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E3%80%8B%E7%AC%AC%E4%B8%89%E6%96%B9%E7%99%BB%E5%BD%95%E5%AE%9E%E8%B7%B5-%E9%99%84%E5%89%8D%E5%90%8E%E7%AB%AF%E5%AE%8C%E6%95%B4%E8%BF%87%E7%A8%8B%E5%8F%8A%E6%B5%8B%E8%AF%95/" class="sidebar-link">《贯穿设计模式》第三方登录实践[附前后端完整过程及测试]</a></li><li><a href="/websocket-spring-sseemitter3-%E5%AE%9E%E7%8E%B0%E8%AE%AF%E9%A3%9E%E6%98%9F%E7%81%ABjava%E5%AE%A2%E6%88%B7%E7%AB%AF/" class="sidebar-link">Websocket.+ Spring-SseEmitter3 实现讯飞星火Java客户端</a></li><li><a href="/%E7%94%A8%E5%B8%83%E9%9A%86%E8%BF%87%E6%BB%A4%E5%99%A8%E5%AE%9E%E7%8E%B0%E6%A3%80%E6%9F%A5%E7%94%A8%E6%88%B7%E5%90%8D%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8-%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C/" class="sidebar-link">用布隆过滤器实现检查用户名是否存在(用户注册)</a></li><li><a href="/springsecurity-%E6%95%B4%E5%90%88-oauth2/" class="sidebar-link">SpringSecurity 整合 Oauth2</a></li><li><a href="/%E5%89%8D%E7%AB%AF%E5%88%9D%E5%A7%8B%E5%8C%96-ant-design-pro-%E7%AC%94%E8%AE%B0/" class="sidebar-link">前端初始化 Ant Design Pro 笔记</a></li><li><a href="/liteflow-%E7%BC%96%E6%8E%92%E5%BC%8F%E7%BC%96%E7%A8%8B%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D/" class="sidebar-link">LiteFlow 编排式编程简单介绍</a></li><li><a href="/%E5%9F%BA%E4%BA%8E-redis-%E5%AE%9E%E7%8E%B0%E7%9F%AD%E4%BF%A1%E7%99%BB%E5%BD%95/" class="sidebar-link">基于 Redis 实现短信登录</a></li><li><a href="/mysql-%E4%B8%80%E6%A3%B5-b-%E6%A0%91%E5%8F%AF%E4%BB%A5%E5%AD%98%E5%A4%9A%E5%B0%91%E6%9D%A1%E6%95%B0%E6%8D%AE/" class="sidebar-link">MySQL 一棵 B + 树可以存多少条数据？</a></li><li><a href="/springboot-%E6%95%B4%E5%90%88-elk-%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E9%87%87%E9%9B%86%E4%B8%8E%E7%9B%91%E6%8E%A7/" class="sidebar-link">SpringBoot 整合 ELK 实现日志采集与监控</a></li><li><a href="/%E5%9F%BA%E4%BA%8E%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B3%A8%E8%A7%A3%E7%9A%84-redisson-%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81%E5%AE%9E%E7%8E%B0/" class="sidebar-link">基于自定义注解的 Redisson 分布式锁实现</a></li><li><a href="/%E7%8E%A9%E8%BD%AC%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%88%A9%E5%99%A8-completablefuture/" class="sidebar-link">玩转异步编程利器 CompletableFuture</a></li><li><a href="/%E9%80%9A%E8%BF%87-windows-%E8%84%9A%E6%9C%AC%E6%89%A7%E8%A1%8C%E6%89%93%E5%8C%85%E6%93%8D%E4%BD%9C/" class="sidebar-link">通过 Windows 脚本执行打包操作</a></li><li><a href="/%E9%98%BF%E9%87%8C%E4%BA%91%E5%AF%B9%E8%B1%A1%E5%AD%98%E5%82%A8-oss/" class="sidebar-link">阿里云对象存储 OSS</a></li><li><a href="/%E5%90%8E%E7%AB%AF-spring-boot-%E4%B8%87%E7%94%A8%E6%A8%A1%E6%9D%BF%E4%BD%BF%E7%94%A8/" class="sidebar-link">后端 Spring Boot 万用模板使用</a></li><li><a href="/%E4%BD%BF%E7%94%A8-canal-%E5%AE%9E%E7%8E%B0%E5%A2%9E%E9%87%8F%E8%AE%A2%E9%98%85%E5%92%8C%E6%B6%88%E8%B4%B9/" class="sidebar-link">使用 canal 实现增量订阅和消费</a></li><li><a href="/springboot-quartz-%E7%AE%80%E6%98%93%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1/" class="sidebar-link">SpringBoot + Quartz 简易定时任务</a></li><li><a href="/string-%E7%9A%84-intern-%E6%96%B9%E6%B3%95/" class="sidebar-link">String 的 intern() 方法</a></li><li><a href="/mysql-%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F%E8%BD%AC%E6%8D%A2/" class="sidebar-link">MySQL 字符串日期格式转换</a></li><li><a href="/fail-fast-%E6%9C%BA%E5%88%B6%E6%98%AF%E4%BB%80%E4%B9%88/" class="sidebar-link">fail-fast 机制是什么？</a></li><li><a href="/%E5%8D%81%E7%A7%8D-sql-%E7%9A%84%E5%86%99%E6%B3%95/" class="sidebar-link">十种 SQL 的写法</a></li><li><a href="/mybatis-%E6%95%B4%E5%90%88%E5%A4%9A%E6%95%B0%E6%8D%AE%E6%BA%90/" class="sidebar-link">MyBatis 整合多数据源</a></li><li><a href="/_1%E7%A7%92%E5%B0%86%E6%9C%AC%E5%9C%B0springboot%E9%A1%B9%E7%9B%AEjar%E5%8C%85%E9%83%A8%E7%BD%B2%E5%88%B0linux%E7%8E%AF%E5%A2%83/" class="sidebar-link">1秒将本地SpringBoot项目jar包部署到Linux环境</a></li><li><a href="/ddd-%E6%98%AF%E4%BB%80%E4%B9%88/" class="sidebar-link">DDD 是什么？</a></li><li><a href="/oracle%E5%88%B0mysql%E5%87%BD%E6%95%B0%E6%9B%BF%E6%8D%A2%E6%96%B9%E6%A1%88%E6%B1%87%E6%80%BB/" class="sidebar-link">Oracle 到 MySQL 函数替换方案汇总</a></li><li><a href="/springboot-%E5%BC%95%E5%85%A5-nacos-windows-%E7%89%88/" class="sidebar-link">Springboot 引入 Nacos ( Windows 版)</a></li><li><a href="/%E5%88%A9%E7%94%A8%E5%B1%80%E5%9F%9F%E7%BD%91%E6%90%AD%E5%BB%BA%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%AE%BF%E9%97%AE%E9%A1%B9%E7%9B%AE/" class="sidebar-link">利用局域网搭建虚拟机实现访问项目</a></li><li><a href="/%E6%B5%85%E8%B0%88-cookie-%E5%92%8C-session/" class="sidebar-link">浅谈 cookie 和 session</a></li><li><a href="/%E7%94%A8-qq-%E9%82%AE%E7%AE%B1%E5%AE%9E%E7%8E%B0%E9%AA%8C%E8%AF%81%E7%A0%81%E5%8A%9F%E8%83%BD/" class="sidebar-link">用 QQ 邮箱实现验证码功能</a></li><li><a href="/redis-%E5%AE%9E%E7%8E%B0%E6%96%87%E7%AB%A0%E7%82%B9%E8%B5%9E%E5%8A%9F%E8%83%BD-%E9%99%84%E5%B8%A6%E5%89%8D%E5%90%8E%E7%AB%AF%E4%BB%A3%E7%A0%81%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/" class="sidebar-link">Redis 实现文章点赞功能(附带前后端代码、数据库)</a></li><li><a href="/%E9%98%BF%E9%87%8C%E4%BA%91%E7%9F%AD%E4%BF%A1%E6%9C%8D%E5%8A%A1%E5%AE%9E%E7%8E%B0%E6%89%8B%E6%9C%BA%E9%AA%8C%E8%AF%81%E7%A0%81/" class="sidebar-link">阿里云短信服务实现手机验证码</a></li><li><a href="/%E3%80%90ajax%E3%80%91%E5%BC%82%E6%AD%A5%E9%80%9A%E4%BF%A1/" class="sidebar-link">【Ajax】异步通信</a></li><li><a href="/%E3%80%90%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E3%80%91%E4%B8%83%E5%A4%A7%E8%AE%BE%E8%AE%A1%E5%8E%9F%E5%88%99/" class="sidebar-link">【设计模式】七大设计原则</a></li><li><a href="/%E6%96%87%E7%AB%A0%E8%AF%84%E8%AE%BA%E5%8A%9F%E8%83%BD%E5%89%8D%E5%90%8E%E7%AB%AF%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88%E6%80%BB%E7%BB%93/" class="sidebar-link">文章评论功能前后端实现方案总结</a></li><li><a href="/%E3%80%90%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E3%80%91git%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B/" class="sidebar-link">【版本控制】Git快速上手</a></li><li><a href="/%E3%80%90java%E5%9F%BA%E7%A1%80%E3%80%91%E6%B6%88%E7%81%AD%E9%AD%94%E6%B3%95%E5%80%BC-%E5%B8%B8%E9%87%8F-%E6%9E%9A%E4%B8%BE%E8%AF%A6%E8%BF%B0/" class="sidebar-link">【Java基础】消灭魔法值-常量&amp;枚举详述</a></li><li><a href="/mysql-%E7%9A%84-char-%E5%B9%B6%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%98%AF%E5%AE%9A%E9%95%BF/" class="sidebar-link">MySQL 的 Char 并不一定是定长</a></li><li><a href="/textcnn-%E6%96%87%E6%9C%AC%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%9C%A8%E6%96%87%E7%AB%A0%E8%AF%84%E8%AE%BA%E5%AE%A1%E6%A0%B8%E4%B8%AD%E7%9A%84%E5%AE%9E%E7%8E%B0%E4%B8%8E%E9%83%A8%E7%BD%B2/" class="sidebar-link">TextCNN 文本分类模型在文章评论审核中的实现与部署</a></li><li><a href="/%E7%90%86%E8%A7%A3-io-%E5%A4%9A%E8%B7%AF%E5%A4%8D%E7%94%A8/" class="sidebar-link">理解 IO 多路复用</a></li><li><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/" aria-current="page" class="active sidebar-link">ElasticSearch 基础概念与入门使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#前言" class="sidebar-link">前言</a></li><li class="sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基础概念" class="sidebar-link">基础概念</a></li><li class="sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#安装" class="sidebar-link">安装</a></li><li class="sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#使用" class="sidebar-link">使用</a></li></ul></li><li><a href="/%E7%90%86%E8%A7%A3%E8%BF%9B%E7%A8%8B-%E7%BA%BF%E7%A8%8B-%E5%8D%8F%E7%A8%8B/" class="sidebar-link">理解进程，线程，协程</a></li><li><a href="/%E7%90%86%E8%A7%A3%E5%8E%9F%E7%A0%81%E3%80%81%E5%8F%8D%E7%A0%81%E3%80%81%E8%A1%A5%E7%A0%81/" class="sidebar-link">理解原码、反码、补码</a></li><li><a href="/%E5%AE%9A%E4%B9%89api%E5%B9%B6%E7%94%9F%E6%88%90%E4%BB%A3%E7%A0%81-go-%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%A1%86%E6%9E%B6-kratos/" class="sidebar-link">定义API并生成代码（ Go 微服务框架 Kratos ）</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="content"><div style="width:100%"><div class="theme-default-content custom-content content__default"><h1 id="elasticsearch-基础概念与入门使用"><a href="#elasticsearch-基础概念与入门使用" class="header-anchor">#</a> ElasticSearch 基础概念与入门使用</h1> <blockquote><p>作者：<a href="https://blog.csdn.net/Go_ahead_forever" target="_blank" rel="noopener noreferrer">为<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，<a href="https://wx.zsxq.com/dweb2/index/group/51122858222824" target="_blank" rel="noopener noreferrer">编程导航星球<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 编号 14255</p></blockquote> <p>elasticsearch 是一款非常强大的开源搜索引擎，具备非常多强大的功能，可以帮助我们从海量的数据中快速找到需要的内容。在电商网站搜索商品在 Google 搜索答案……elasticsearch结合kibana、Logstash、Beats，也就是elastic stack（ELK）。被广泛应用在日志数据分析、实时监控等领域。</p> <h2 id="前言"><a href="#前言" class="header-anchor">#</a> 前言</h2> <p>elasticsearch 是一款非常强大的开源搜索引擎，具备非常多强大的功能，可以帮助我们从海量的数据中快速找到需要的内容。</p> <p>例如：</p> <ul><li>在 Github 中搜索代码</li></ul> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549217.png" loading="lazy" class="lazy"></p> <ul><li>在电商网站搜索商品</li></ul> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549383.png" loading="lazy" class="lazy"></p> <ul><li>在 Google 搜索答案</li></ul> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549223.png" loading="lazy" class="lazy"></p> <ul><li>……</li></ul> <p>elasticsearch结合kibana、Logstash、Beats，也就是elastic stack（ELK）。被广泛应用在日志数据分析、实时监控等领域，而elasticsearch是elastic stack的核心，负责存储、搜索、分析数据。</p> <p>elasticsearch底层是基于<strong>lucene</strong>来实现的。</p> <p><strong>Lucene</strong>是一个Java语言的搜索引擎类库，是Apache公司的顶级项目，由DougCutting于1999年研发。官网地址：https://lucene.apache.org/ 。</p> <h2 id="基础概念"><a href="#基础概念" class="header-anchor">#</a> 基础概念</h2> <h3 id="文档"><a href="#文档" class="header-anchor">#</a> 文档</h3> <p>elasticsearch 是面向 <strong>文档</strong> 存储的，可以是数据库中的一条商品数据，一个订单信息。文档数据会被序列化成 json 格式后存储在 elasticsearch 中，而 json 文档中往往包含很多的字段（Field），类似于数据库中的列。</p> <h3 id="分词器"><a href="#分词器" class="header-anchor">#</a> 分词器</h3> <p>作用：</p> <ul><li>创建倒排索引时对文档分词</li> <li>用户搜索时，对输入的内容分词</li></ul> <h3 id="索引与映射"><a href="#索引与映射" class="header-anchor">#</a> 索引与映射</h3> <p><strong>索引（Index）</strong> ，就是相同类型的文档的集合。</p> <p>例如：</p> <ul><li>所有用户文档，就可以组织在一起，称为用户的索引；</li> <li>所用商品的文档，可以组织在一起，称为商品的索引；</li> <li>所有订单的文档，可以组织在一起，称为订单的索引；</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 商品索引
<span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;电视机&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;category&quot;</span><span class="token operator">:</span> <span class="token string">&quot;家电&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token number">599.99</span><span class="token punctuation">,</span>
    <span class="token property">&quot;stock&quot;</span><span class="token operator">:</span> <span class="token number">50</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;手机&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;category&quot;</span><span class="token operator">:</span> <span class="token string">&quot;电子设备&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token number">899.99</span><span class="token punctuation">,</span>
    <span class="token property">&quot;stock&quot;</span><span class="token operator">:</span> <span class="token number">100</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;运动鞋&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;category&quot;</span><span class="token operator">:</span> <span class="token string">&quot;服装&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token number">79.99</span><span class="token punctuation">,</span>
    <span class="token property">&quot;stock&quot;</span><span class="token operator">:</span> <span class="token number">200</span>
  <span class="token punctuation">}</span>
# 用户索引
<span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;电视机&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;category&quot;</span><span class="token operator">:</span> <span class="token string">&quot;家电&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token number">599.99</span><span class="token punctuation">,</span>
    <span class="token property">&quot;stock&quot;</span><span class="token operator">:</span> <span class="token number">50</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;手机&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;category&quot;</span><span class="token operator">:</span> <span class="token string">&quot;电子设备&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token number">899.99</span><span class="token punctuation">,</span>
    <span class="token property">&quot;stock&quot;</span><span class="token operator">:</span> <span class="token number">100</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;运动鞋&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;category&quot;</span><span class="token operator">:</span> <span class="token string">&quot;服装&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token number">79.99</span><span class="token punctuation">,</span>
    <span class="token property">&quot;stock&quot;</span><span class="token operator">:</span> <span class="token number">200</span>
  <span class="token punctuation">}</span>
# 订单索引
<span class="token punctuation">{</span>
    <span class="token property">&quot;order_id&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;user_id&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;products&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;product_id&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
        <span class="token property">&quot;quantity&quot;</span><span class="token operator">:</span> <span class="token number">2</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;product_id&quot;</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
        <span class="token property">&quot;quantity&quot;</span><span class="token operator">:</span> <span class="token number">1</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;total_price&quot;</span><span class="token operator">:</span> <span class="token number">2099.97</span><span class="token punctuation">,</span>
    <span class="token property">&quot;order_date&quot;</span><span class="token operator">:</span> <span class="token string">&quot;2023-12-10&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;shipping_address&quot;</span><span class="token operator">:</span> <span class="token string">&quot;上海市&quot;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;order_id&quot;</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
    <span class="token property">&quot;user_id&quot;</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
    <span class="token property">&quot;products&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
        <span class="token property">&quot;product_id&quot;</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
        <span class="token property">&quot;quantity&quot;</span><span class="token operator">:</span> <span class="token number">3</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;total_price&quot;</span><span class="token operator">:</span> <span class="token number">239.97</span><span class="token punctuation">,</span>
    <span class="token property">&quot;order_date&quot;</span><span class="token operator">:</span> <span class="token string">&quot;2023-12-15&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;shipping_address&quot;</span><span class="token operator">:</span> <span class="token string">&quot;广州市&quot;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br></div></div><p>因此，我们可以把索引当作是数据库中的表。</p> <p>数据库的表会有约束信息，用来定义表的结构、字段的名称、类型等信息。因此，索引库中就有<strong>映射（mapping）</strong>，是索引中文档的字段约束信息，类似表的结构约束。</p> <h3 id="mysql-与-elasticsearch-一些概念的对比"><a href="#mysql-与-elasticsearch-一些概念的对比" class="header-anchor">#</a> mysql 与 elasticsearch 一些概念的对比</h3> <table><thead><tr><th><strong>MySQL</strong></th> <th><strong>Elasticsearch</strong></th> <th><strong>说明</strong></th></tr></thead> <tbody><tr><td>Table</td> <td>Index</td> <td>索引(index)，就是文档的集合，类似数据库的表(table)</td></tr> <tr><td>Row</td> <td>Document</td> <td>文档（Document），就是一条条的数据，类似数据库中的行（Row），文档都是JSON格式</td></tr> <tr><td>Column</td> <td>Field</td> <td>字段（Field），就是JSON文档中的字段，类似数据库中的列（Column）</td></tr> <tr><td>Schema</td> <td>Mapping</td> <td>Mapping（映射）是索引中文档的约束，例如字段类型约束。类似数据库的表结构（Schema）</td></tr> <tr><td>SQL</td> <td>DSL</td> <td>DSL是elasticsearch提供的JSON风格的请求语句，用来操作elasticsearch，实现CRUD</td></tr></tbody></table> <p>是不是说，我们学习了elasticsearch就不再需要mysql了呢？</p> <p>并不是如此，两者各自有自己的擅长支出：</p> <ul><li>Mysql：擅长事务类型操作，可以确保数据的安全和一致性</li> <li>Elasticsearch：擅长海量数据的搜索、分析、计算</li></ul> <p>因此在企业中，往往是两者结合使用：</p> <ul><li>对安全性要求较高的写操作，使用mysql实现</li> <li>对查询性能要求较高的搜索需求，使用elasticsearch实现</li> <li>两者再基于某种方式，实现数据的同步，保证一致性</li></ul> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549107.png" loading="lazy" class="lazy"></p> <h2 id="安装"><a href="#安装" class="header-anchor">#</a> 安装</h2> <p>关于安装的话，这里提供 Windows 版本，一个是elasticsearch、一个是 kibana （一个工具）。</p> <p><a href="https://blog.csdn.net/Go_ahead_forever/article/details/133720298" target="_blank" rel="noopener noreferrer">安装参考<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h3 id="安装中文分词器"><a href="#安装中文分词器" class="header-anchor">#</a> 安装中文分词器</h3> <p>elasticsearch 对中文的分词不是很友好，一般的分词不管你选择的是标准分词器，还是中文分词器，结果都是只能分成一个一个的字，非常不友好。所以我们选择一个开源的分词器。[下载地址](<a href="https://github.com/medcl/elasticsearch-analysis-ik" target="_blank" rel="noopener noreferrer">medcl/elasticsearch-analysis-ik: The IK Analysis plugin integrates Lucene IK analyzer into elasticsearch, support customized dictionary. (github.com)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>) 你只需要把内容下载好，把这个目录解压放到安装 elasticsearch 的文件夹中的 plugins 目录中。例如：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549138.png" loading="lazy" class="lazy"></p> <p>放好以后，直接重启 elasticsearch 就好。</p> <p>如果出现报错说分词器版本不兼容 elasticsearch 只要进入下载好的分词器目录下面的 <code>plugin-descriptor.properties</code>文件中八版本改成和你的 elasticsearch 版本一致就好了。</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549316.png" loading="lazy" class="lazy"></p> <h2 id="使用"><a href="#使用" class="header-anchor">#</a> 使用</h2> <p>了解了上面的一些信息以后，我们接下来就开始使用 elasticsearch 吧。</p> <h3 id="索引的增删改查"><a href="#索引的增删改查" class="header-anchor">#</a> 索引的增删改查</h3> <p>索引库就类似数据库表，mapping映射就类似表的结构。</p> <p>我们要向es中存储数据，必须先创建“库”和“表”。</p> <h4 id="mapping-映射属性"><a href="#mapping-映射属性" class="header-anchor">#</a> mapping 映射属性</h4> <p>mapping是对索引库中文档的约束，常见的mapping属性包括：</p> <ul><li>type：字段数据类型，常见的简单类型有：
<ul><li>字符串：text（可分词的文本）、keyword（精确值，例如：品牌、国家、ip地址）</li> <li>数值：long、integer、short、byte、double、float、</li> <li>布尔：boolean</li> <li>日期：date</li> <li>对象：object</li></ul></li> <li>index：是否创建索引，默认为true</li> <li>analyzer：使用哪种分词器</li> <li>properties：该字段的子字段</li></ul> <p>例如：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;age&quot;</span><span class="token operator">:</span> <span class="token number">21</span><span class="token punctuation">,</span>
    <span class="token property">&quot;weight&quot;</span><span class="token operator">:</span> <span class="token number">52.1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;isMarried&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
    <span class="token property">&quot;info&quot;</span><span class="token operator">:</span> <span class="token string">&quot;created by xwhking&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;email&quot;</span><span class="token operator">:</span> <span class="token string">&quot;2837468248@qq.com&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;score&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">99.1</span><span class="token punctuation">,</span> <span class="token number">99.5</span><span class="token punctuation">,</span> <span class="token number">98.9</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;firstName&quot;</span><span class="token operator">:</span> <span class="token string">&quot;XWH&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;lastName&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Z&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>对应的每个字段映射（mapping）：</p> <ul><li>age：类型为 integer；参与搜索，因此需要index为true；无需分词器</li> <li>weight：类型为float；参与搜索，因此需要index为true；无需分词器</li> <li>isMarried：类型为boolean；参与搜索，因此需要index为true；无需分词器</li> <li>info：类型为字符串，需要分词，因此是text；参与搜索，因此需要index为true；分词器可以用ik_smart</li> <li>email：类型为字符串，但是不需要分词，因此是keyword；不参与搜索，因此需要index为false；无需分词器</li> <li>score：虽然是数组，但是我们只看元素的类型，类型为float；参与搜索，因此需要index为true；无需分词器</li> <li>name：类型为object，需要定义多个子属性
<ul><li>name.firstName；类型为字符串，但是不需要分词，因此是keyword；参与搜索，因此需要index为true；无需分词器</li> <li>name.lastName；类型为字符串，但是不需要分词，因此是keyword；参与搜索，因此需要index为true；无需分词器</li></ul></li></ul> <h4 id="创建索引库和映射"><a href="#创建索引库和映射" class="header-anchor">#</a> 创建索引库和映射</h4> <h5 id="基本语法"><a href="#基本语法" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方式： PUT</li> <li>请求路径：/{索引库名}， 可以自定义</li> <li>请求参数：mapping 映射</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /索引库名称
<span class="token punctuation">{</span>
  <span class="token property">&quot;mappings&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;字段名&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;analyzer&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ik_smart&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;字段名2&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;keyword&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token string">&quot;false&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;字段名3&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;子字段&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;keyword&quot;</span>
          <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token comment">// ...略</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h5 id="示例-以上面的数据为例-我们所有的操作都在-kibana-的中-dev-tools-中完成"><a href="#示例-以上面的数据为例-我们所有的操作都在-kibana-的中-dev-tools-中完成" class="header-anchor">#</a> 示例（以上面的数据为例，我们所有的操作都在 Kibana 的中 dev tools 中完成）</h5> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /xwhking
<span class="token punctuation">{</span>
  <span class="token property">&quot;mappings&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;integer&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;weight&quot;</span> <span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;float&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;isMarrid&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;boolean&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;info&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;analyzer&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ik_smart&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;email&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;keyword&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;score&quot;</span> <span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;float&quot;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;firstname&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;type&quot;</span><span class="token operator">:</span><span class="token string">&quot;keyword&quot;</span> 
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token property">&quot;lastname&quot;</span> <span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;type&quot;</span><span class="token operator">:</span><span class="token string">&quot;keyword&quot;</span>
          <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br></div></div><p>结果展示：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549968.png" loading="lazy" class="lazy"></p> <h4 id="查询索引库"><a href="#查询索引库" class="header-anchor">#</a> 查询索引库</h4> <h5 id="基本语法-2"><a href="#基本语法-2" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方式：GET</li> <li>请求路径：/索引库名</li> <li>请求参数：无</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /索引库名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>示例(上面创建的索引库)：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /xwhking
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>结果展示：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549009.png" loading="lazy" class="lazy"></p> <h4 id="修改索引库"><a href="#修改索引库" class="header-anchor">#</a> 修改索引库</h4> <p>倒排索引结构虽然不复杂，但是一旦数据结构改变（比如改变了分词器），就需要重新创建倒排索引，这简直是灾难。因此索引库<strong>一旦创建，无法修改mapping</strong>。</p> <p>虽然无法修改mapping中已有的字段，但是却允许添加新的字段到mapping中，因为不会对倒排索引产生影响。</p> <h5 id="基本语法-3"><a href="#基本语法-3" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方法：PUT</li> <li>请求路径：/索引库名/_mapping</li> <li>请求参数：properties （看下面的例子）</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /索引库名/_mapping
<span class="token punctuation">{</span>
  <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;新字段名&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
      <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;integer&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>示例：</p> <p>为上面创建的索引添加一个 major 字段（Field）</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 为索引添加字段
PUT /xwhking/_mapping
<span class="token punctuation">{</span>
  <span class="token property">&quot;properties&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;major&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;type&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;keyword&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>添加结果：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549979.png" loading="lazy" class="lazy"></p> <p>我们重新查看索引看是否有添加字段：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549472.png" loading="lazy" class="lazy"></p> <p>从结果来看我们是成功了的。</p> <h4 id="删除索引库"><a href="#删除索引库" class="header-anchor">#</a> 删除索引库</h4> <h5 id="基本语法-4"><a href="#基本语法-4" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方式：DELETE</li> <li>请求路径：/索引库名</li> <li>请求参数： 无</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>DELETE /索引库名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>例子：</p> <p>我们删除我们上面传创建的索引库，然后再去查询，看是否能够查询的到</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>DELETE /xwhking
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>结果：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549476.png" loading="lazy" class="lazy"></p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549946.png" loading="lazy" class="lazy"></p> <p>很明显我们查询不到了。</p> <h3 id="文档的增删改查"><a href="#文档的增删改查" class="header-anchor">#</a> 文档的增删改查</h3> <h4 id="新增文档"><a href="#新增文档" class="header-anchor">#</a> 新增文档</h4> <h5 id="基本语法-5"><a href="#基本语法-5" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方式：POST</li> <li>请求路径：/索引库名/_doc/文档id <code>注意这里的文档 id，如果不填，elasticsearch系统会自动帮你添加一个随机的 id 值</code></li> <li>请求参数：一条以 <code>json</code> 为格式的数据采用键值对方式</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>POST /索引库名/_doc/文档id
<span class="token punctuation">{</span>
    <span class="token property">&quot;字段1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;值1&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;字段2&quot;</span><span class="token operator">:</span> <span class="token string">&quot;值2&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;字段3&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;子属性1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;值3&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;子属性2&quot;</span><span class="token operator">:</span> <span class="token string">&quot;值4&quot;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>例子：</p> <p>我们再把上面删除的索引重新创建一下，把最开始的那条数据插入试试</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 创建一个文档
POST /xwhking/_doc/<span class="token number">1</span>
<span class="token punctuation">{</span>
  <span class="token property">&quot;age&quot;</span><span class="token operator">:</span><span class="token number">21</span><span class="token punctuation">,</span>
  <span class="token property">&quot;weight&quot;</span><span class="token operator">:</span><span class="token number">52.1</span><span class="token punctuation">,</span>
  <span class="token property">&quot;isMarried&quot;</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">,</span>
  <span class="token property">&quot;info&quot;</span><span class="token operator">:</span><span class="token string">&quot;created by xwhking&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;email&quot;</span><span class="token operator">:</span><span class="token string">&quot;2837468248@qq.com&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;score&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span><span class="token number">99.1</span><span class="token punctuation">,</span> <span class="token number">99.5</span><span class="token punctuation">,</span> <span class="token number">98.9</span><span class="token punctuation">]</span><span class="token punctuation">,</span> 
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
      <span class="token property">&quot;firstName&quot;</span><span class="token operator">:</span><span class="token string">&quot;XWH&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;lastName&quot;</span><span class="token operator">:</span><span class="token string">&quot;Z&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><blockquote><p>这里可能会有一个疑问：就是为什么我明明定义 score 的时候只是一个 float 类型，为什么在插入文档的时候就能插入一个数组呢？这是由 elasticsearch 决定的，因为elasticsearch 没有数组这个数据类型，所以就允许接受一个字段的多个值。</p></blockquote> <p>结果：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549932.png" loading="lazy" class="lazy"></p> <h4 id="查询文档"><a href="#查询文档" class="header-anchor">#</a> 查询文档</h4> <h5 id="基本语法-6"><a href="#基本语法-6" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方式：GET</li> <li>请求路径：/索引库名/_doc/文档id</li> <li>请求参数：无</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /<span class="token punctuation">{</span>索引库名称<span class="token punctuation">}</span>/_doc/<span class="token punctuation">{</span>id<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>示例：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /xwhking/_doc/<span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>结果：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549969.png" loading="lazy" class="lazy"></p> <h4 id="删除文档"><a href="#删除文档" class="header-anchor">#</a> 删除文档</h4> <h5 id="基本语法-7"><a href="#基本语法-7" class="header-anchor">#</a> 基本语法：</h5> <ul><li>请求方式：DELETE</li> <li>请求路径：/索引库名/_doc/文档id</li> <li>请求参数：无</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>DELETE /<span class="token punctuation">{</span>索引库名<span class="token punctuation">}</span>/_doc/id值
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>示例</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>DELETE /xwhking/_doc/<span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>结果参考</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549116.png" loading="lazy" class="lazy"></p> <h4 id="修改文档"><a href="#修改文档" class="header-anchor">#</a> 修改文档</h4> <p>修改有两种方式：</p> <ul><li>全量修改：直接覆盖原来的文档</li> <li>增量修改：修改文档中的部分字段</li></ul> <h5 id="全量修改"><a href="#全量修改" class="header-anchor">#</a> 全量修改</h5> <p>全量修改是覆盖原来的文档，其本质是：</p> <ul><li>根据指定的id删除文档</li> <li>新增一个相同id的文档</li></ul> <p><strong>注意</strong>：如果根据id删除时，id不存在，第二步的新增也会执行，也就从修改变成了新增操作了。</p> <h6 id="基本语法-8"><a href="#基本语法-8" class="header-anchor">#</a> 基本语法：</h6> <ul><li>请求方式：PUT</li> <li>请求路径：/索引库名/_doc/文档id</li> <li>请求参数：把所有文档信息要修改的进行修改，并且没有修改的也需要</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /<span class="token punctuation">{</span>索引库名<span class="token punctuation">}</span>/_doc/文档id
<span class="token punctuation">{</span>
    <span class="token property">&quot;字段1&quot;</span><span class="token operator">:</span> <span class="token string">&quot;值1&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;字段2&quot;</span><span class="token operator">:</span> <span class="token string">&quot;值2&quot;</span><span class="token punctuation">,</span>
    <span class="token comment">// ... 略</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>示例：</p> <p>我们改变一下上面文档的邮箱</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /xwhking/_doc/<span class="token number">1</span>
<span class="token punctuation">{</span>
    <span class="token property">&quot;age&quot;</span><span class="token operator">:</span> <span class="token number">21</span><span class="token punctuation">,</span>
    <span class="token property">&quot;weight&quot;</span><span class="token operator">:</span> <span class="token number">52.1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;isMarried&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
    <span class="token property">&quot;info&quot;</span><span class="token operator">:</span> <span class="token string">&quot;created by xwhking&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;email&quot;</span><span class="token operator">:</span> <span class="token string">&quot;https://www.github.com/xwhking&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;score&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">99.1</span><span class="token punctuation">,</span> <span class="token number">99.5</span><span class="token punctuation">,</span> <span class="token number">98.9</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;firstName&quot;</span><span class="token operator">:</span> <span class="token string">&quot;XWH&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;lastName&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Z&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>结果：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549126.png" loading="lazy" class="lazy"></p> <h5 id="增量修改"><a href="#增量修改" class="header-anchor">#</a> 增量修改</h5> <p>增量修改是只修改指定id匹配的文档中的部分字段。</p> <h6 id="基本语法-9"><a href="#基本语法-9" class="header-anchor">#</a> 基本语法：</h6> <ul><li>请求方式：POST</li> <li>请求路径：/索引库名/_update/文档id</li> <li>请求参数：doc 内容是要修改的字段，以及新的值</li></ul> <p>基本格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>POST /<span class="token punctuation">{</span>索引库名<span class="token punctuation">}</span>/_update/文档id
<span class="token punctuation">{</span>
    <span class="token property">&quot;doc&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
         <span class="token property">&quot;字段名&quot;</span><span class="token operator">:</span> <span class="token string">&quot;新的值&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>示例（我们再把邮箱改回来）：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 修改文档，增量修改
POST /xwhking/_doc/<span class="token number">1</span>
<span class="token punctuation">{</span>
  <span class="token property">&quot;doc&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;email&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;2837468248@qq..com&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>其中的 version 表示修改次数，创建一次，上面一次全量修改一次，增量修改一次，所以是三次。</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549810.png" loading="lazy" class="lazy"></p> <h3 id="利用-restapi-在-java-中使用-elasticsearch"><a href="#利用-restapi-在-java-中使用-elasticsearch" class="header-anchor">#</a> 利用 RestAPI 在 Java 中使用 ElasticSearch</h3> <p>这里暂不介绍如何使用，具体使用其实看一下官方文档，或者直接按照代码提示就可以做了，我们现在只要知道ElasticSearch原生的用法，再去用 Client 就很容易上手、理解。我们这里只稍微带一下在 Java 项目中如何引入。</p> <p>三步：</p> <ol><li><p>引入依赖</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.elasticsearch.client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>elasticsearch-rest-high-level-client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li> <li><p>因为 springboot 可能管理了 elasticsearch的版本，所以我们需要把这个版本依赖覆盖掉，并且改成我们自己 elasticsearch的版本</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>properties</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>java.version</span><span class="token punctuation">&gt;</span></span>1.8<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>java.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>elasticsearch.version</span><span class="token punctuation">&gt;</span></span>7.12.1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>elasticsearch.version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>properties</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li> <li><p>初始化 RestHighLevelClient</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">RestHighLevelClient</span> client <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RestHighLevelClient</span><span class="token punctuation">(</span><span class="token class-name">RestClient</span><span class="token punctuation">.</span><span class="token function">builder</span><span class="token punctuation">(</span>
        <span class="token class-name">HttpHost</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token string">&quot;http://192.168.150.101:9200&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></li></ol> <blockquote><h1 id="tips"><a href="#tips" class="header-anchor">#</a> TIPS</h1> <p>Elasticsearch 中特殊的数据类型</p> <p>ES中支持两种地理坐标数据类型：</p> <ul><li>geo_point: 由纬度(latitude)和经度(longitude)确定的一个点。例如：&quot;32.8752345,120.2981576&quot;</li> <li>ge0_shape :有多个ge0_point组成的复杂几何图形。例如一条直线，&quot;LINESTRING(-77.0365338.897676,-77.00905138.889939)&quot;</li></ul> <p>字段拷贝可以使用copy to属性将当前字段拷贝到指定字段。示例：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;a11&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
		<span class="token property">&quot;type&quot;</span><span class="token operator">:</span><span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
		<span class="token property">&quot;analyzer&quot;</span><span class="token operator">:</span><span class="token string">&quot;ik_max_word&quot;</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token property">&quot;brand&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
		<span class="token property">&quot;type&quot;</span><span class="token operator">:</span><span class="token string">&quot;keyword&quot;</span><span class="token punctuation">,</span>
		<span class="token property">&quot;copy_to&quot;</span><span class="token operator">:</span><span class="token string">&quot;all&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div></blockquote> <h3 id="如何搜索-dsl查询文档"><a href="#如何搜索-dsl查询文档" class="header-anchor">#</a> 如何搜索 ==&gt; DSL查询文档</h3> <h4 id="数组准备"><a href="#数组准备" class="header-anchor">#</a> 数组准备</h4> <p>我这里直接开源一个数据初始化的代码，需要的话直接拉下来，然后通过看项目的 README 文件，配置 elasticsearch, 然后把数据放入elasticsearch 我们就开始进行搜索数据。</p> <p><a href="https://github.com/xwhking/elasticsearch-test-data" target="_blank" rel="noopener noreferrer">项目数据地址<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>)</p> <h4 id="dsl-查询分类"><a href="#dsl-查询分类" class="header-anchor">#</a> DSL 查询分类</h4> <p>Elasticsearch提供了基于JSON的DSL（<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html" target="_blank" rel="noopener noreferrer">Domain Specific Language<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>）来定义查询。常见的查询类型包括：</p> <ul><li><strong>查询所有</strong>：查询出所有数据，一般测试用。例如：match_all</li> <li><strong>全文检索（full text）查询</strong>：利用分词器对用户输入内容分词，然后去倒排索引库中匹配。例如：
<ul><li>match_query</li> <li>multi_match_query</li></ul></li> <li><strong>精确查询</strong>：根据精确词条值查找数据，一般是查找keyword、数值、日期、boolean等类型字段。例如：
<ul><li>ids</li> <li>range</li> <li>term</li></ul></li> <li><strong>地理（geo）查询</strong>：根据经纬度查询。例如：
<ul><li>geo_distance</li> <li>geo_bounding_box</li></ul></li> <li><strong>复合（compound）查询</strong>：复合查询可以将上述各种查询条件组合起来，合并查询条件。例如：
<ul><li>bool</li> <li>function_score</li></ul></li></ul> <h5 id="查询基本语法"><a href="#查询基本语法" class="header-anchor">#</a> 查询基本语法：</h5> <ul><li>请求方式： GET</li> <li>请求路径：/索引库/_search</li> <li>请求参数：根据不同请求方式不同</li></ul> <p>基本格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;查询类型&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;查询条件&quot;</span><span class="token operator">:</span> <span class="token string">&quot;条件值&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>示例查询所有：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>结果：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549804.png" loading="lazy" class="lazy"></p> <h4 id="全文检索查询"><a href="#全文检索查询" class="header-anchor">#</a> 全文检索查询</h4> <p>全文检索查询的基本流程如下：</p> <ul><li>对用户搜索的内容做分词，得到词条</li> <li>根据词条去倒排索引库中匹配，得到文档id</li> <li>根据文档id找到文档，返回给用户</li></ul> <p>比较常用的场景包括：</p> <ul><li>商城的输入框搜索</li> <li>百度输入框搜索</li></ul> <blockquote><h1 id="tips-2"><a href="#tips-2" class="header-anchor">#</a> TIPS</h1> <p>因为是拿着词条去匹配，因此参与搜索的字段也必须是可分词的text类型的字段。</p></blockquote> <h5 id="基本语法-10"><a href="#基本语法-10" class="header-anchor">#</a> 基本语法</h5> <ul><li>请求方式： GET</li> <li>请求路径： /索引库/_search</li> <li>请求参数：
<ul><li>match查询：单字段查询</li> <li>multi_match查询：多字段查询，任意一个字段符合条件就算符合查询条件</li></ul></li></ul> <h6 id="基本格式"><a href="#基本格式" class="header-anchor">#</a> 基本格式：</h6> <p><strong>match 查询格式</strong></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /索引库名/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token string">&quot;TEXT&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><strong>multi_match</strong> 查询格式:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;multi_match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token string">&quot;TEXT&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;fields&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;FIELD1&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot; FIELD12&quot;</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>查询示例：</p> <p>match 示例：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;all&quot;</span><span class="token operator">:</span> <span class="token string">&quot;希尔顿&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>result :</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549833.png" loading="lazy" class="lazy"></p> <p>multi_match 示例：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;multi_match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token string">&quot;如家&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;fields&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;brand&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>result:</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549897.png" loading="lazy" class="lazy"></p> <blockquote><h1 id="tips-3"><a href="#tips-3" class="header-anchor">#</a> TIPS</h1> <p>如果这里我们使用同样的查询词，查询出来的结果会是一样的，为什么呢？</p> <p>因为我们将brand、name、business值都利用copy_to复制到了all字段中。因此你根据三个字段搜索，和根据all字段搜索效果当然一样了。</p> <p>但是，搜索字段越多，对查询性能影响越大，因此建议采用copy_to，然后单字段查询的方式。</p></blockquote> <h4 id="精确查询"><a href="#精确查询" class="header-anchor">#</a> 精确查询</h4> <p>精确查询一般是查找keyword、数值、日期、boolean等类型字段。所以<strong>不会</strong>对搜索条件分词。常见的有：</p> <ul><li>term：根据词条精确值查询</li> <li>range：根据值的范围查询</li></ul> <h5 id="term-查询"><a href="#term-查询" class="header-anchor">#</a> Term 查询</h5> <p>因为精确查询的字段搜是不分词的字段，因此查询的条件也必须是<strong>不分词</strong>的词条。查询时，用户输入的内容跟自动值完全匹配时才认为符合条件。如果用户输入的内容过多，反而搜索不到数据。</p> <h6 id="基本语法-11"><a href="#基本语法-11" class="header-anchor">#</a> 基本语法</h6> <ul><li>请求方式： GET</li> <li>请求路径： /索引库/_search</li> <li>请求参数：见示例</li></ul> <p>基本格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token comment">// term查询</span>
GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;value&quot;</span><span class="token operator">:</span> <span class="token string">&quot;VALUE&quot;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>示例：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;city&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;value&quot;</span><span class="token operator">:</span> <span class="token string">&quot;上海&quot;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>result:</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549955.png" loading="lazy" class="lazy"></p> <p>因为词条是精匹配如果我们输入的是<code>杭州上海</code>则不会有结果</p> <p>但是，当我搜索的内容不是词条，而是多个词语形成的短语时，反而搜索不到：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549052.png" loading="lazy" class="lazy"></p> <h5 id="range-查询"><a href="#range-查询" class="header-anchor">#</a> range 查询</h5> <p>范围查询，一般应用在对数值类型做范围过滤的时候。比如做价格范围过滤。</p> <h6 id="基本语法-12"><a href="#基本语法-12" class="header-anchor">#</a> 基本语法</h6> <ul><li>请求方式： GET</li> <li>请求路径： /索引库/_search</li> <li>请求参数: 看具体示例</li></ul> <p>基本格式:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token comment">// range查询</span>
GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;range&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;gte&quot;</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token comment">// 这里的gte代表大于等于，gt则代表大于</span>
        <span class="token property">&quot;lte&quot;</span><span class="token operator">:</span> <span class="token number">20</span> <span class="token comment">// lte代表小于等于，lt则代表小于</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>示例:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;range&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;score&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;gte&quot;</span><span class="token operator">:</span> <span class="token number">40</span><span class="token punctuation">,</span>
        <span class="token property">&quot;lte&quot;</span><span class="token operator">:</span> <span class="token number">3000</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>result:</p> <p>出现的都是在 40 以上的！</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549649.png" loading="lazy" class="lazy"></p> <h4 id=""><a href="#" class="header-anchor">#</a></h4> <h4 id="地理坐标查询"><a href="#地理坐标查询" class="header-anchor">#</a> 地理坐标查询</h4> <p>所谓的地理坐标查询，其实就是根据经纬度查询，官方文档：https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-queries.html</p> <p>常见的使用场景包括：</p> <ul><li>携程：搜索我附近的酒店</li> <li>滴滴：搜索我附近的出租车</li> <li>微信：搜索我附近的人</li></ul> <h5 id="矩形范围查询"><a href="#矩形范围查询" class="header-anchor">#</a> 矩形范围查询</h5> <h6 id="基本语法-13"><a href="#基本语法-13" class="header-anchor">#</a> 基本语法</h6> <ul><li>请求方式：GET</li> <li>请求路径：/索引库/_search</li> <li>请求参数：请看示例</li></ul> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549636.png" loading="lazy" class="lazy"></p> <p>查询时，需要指定矩形的<strong>左上</strong>、<strong>右下</strong>两个点的坐标，然后画出一个矩形，落在该矩形内的都是符合条件的点。</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token comment">// geo_bounding_box查询</span>
GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;geo_bounding_box&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;top_left&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 左上点</span>
          <span class="token property">&quot;lat&quot;</span><span class="token operator">:</span> <span class="token number">31.1</span><span class="token punctuation">,</span>
          <span class="token property">&quot;lon&quot;</span><span class="token operator">:</span> <span class="token number">121.5</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;bottom_right&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 右下点</span>
          <span class="token property">&quot;lat&quot;</span><span class="token operator">:</span> <span class="token number">30.9</span><span class="token punctuation">,</span>
          <span class="token property">&quot;lon&quot;</span><span class="token operator">:</span> <span class="token number">121.7</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h5 id="附近查询"><a href="#附近查询" class="header-anchor">#</a> 附近查询</h5> <p>附近查询，也叫做距离查询（geo_distance）：查询到指定中心点小于某个距离值的所有文档。</p> <p>换句话来说，在地图上找一个点作为圆心，以指定距离为半径，画一个圆，落在圆内的坐标都算符合条件：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549864.png" loading="lazy" class="lazy"></p> <h6 id="基本语法-14"><a href="#基本语法-14" class="header-anchor">#</a> 基本语法：</h6> <ul><li>请求方式：GET</li> <li>请求路径：/索引库/_search</li> <li>请求参数：请看示例</li></ul> <p>格式：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token comment">// geo_distance 查询</span>
GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;geo_distance&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;distance&quot;</span><span class="token operator">:</span> <span class="token string">&quot;15km&quot;</span><span class="token punctuation">,</span> <span class="token comment">// 半径</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token string">&quot;31.21,121.5&quot;</span> <span class="token comment">// 圆心</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>示例：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;geo_distance&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;distance&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;15km&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;location&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;31.21,121.5&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>result:</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549873.png" loading="lazy" class="lazy"></p> <p>缩小一下半径（就是陆家嘴附近啦）：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549909.png" loading="lazy" class="lazy"></p> <h4 id="复合查询"><a href="#复合查询" class="header-anchor">#</a> 复合查询</h4> <p>当我们利用match查询时，文档结果会根据与搜索词条的关联度打分（_score），返回结果时按照分值降序排列。</p> <p>例如，我们搜索 &quot;虹桥如家&quot;，结果如下：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">[</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;_score&quot;</span> <span class="token operator">:</span> <span class="token number">17.850193</span><span class="token punctuation">,</span>
    <span class="token property">&quot;_source&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;虹桥如家酒店真不错&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;_score&quot;</span> <span class="token operator">:</span> <span class="token number">12.259849</span><span class="token punctuation">,</span>
    <span class="token property">&quot;_source&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;外滩如家酒店真不错&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token property">&quot;_score&quot;</span> <span class="token operator">:</span> <span class="token number">11.91091</span><span class="token punctuation">,</span>
    <span class="token property">&quot;_source&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;迪士尼如家酒店真不错&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><p>在elasticsearch中，早期使用的打分算法是TF-IDF算法，公式如下：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549426.png" loading="lazy" class="lazy"></p> <p>在后来的5.1版本升级中，elasticsearch将算法改进为BM25算法，公式如下：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549325.png" loading="lazy" class="lazy"></p> <p>TF-IDF算法有一各缺陷，就是词条频率越高，文档得分也会越高，单个词条对文档影响较大。而BM25则会让单个词条的算分有一个上限，曲线更加平滑：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549529.png" loading="lazy" class="lazy"></p> <h5 id="算分函数查询"><a href="#算分函数查询" class="header-anchor">#</a> 算分函数查询</h5> <p>根据相关度打分是比较合理的需求，但<strong>合理的不一定是产品经理需要</strong>的。</p> <p>以百度为例，你搜索的结果中，并不是相关度越高排名越靠前，而是谁掏的钱多排名就越靠前。</p> <p>要想认为控制相关性算分，就需要利用elasticsearch中的function score 查询了。</p> <h6 id="基本语法-15"><a href="#基本语法-15" class="header-anchor">#</a> 基本语法：</h6> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549584.png" loading="lazy" class="lazy"></p> <p>function score 查询中包含四部分内容：</p> <ul><li><p><strong>原始查询</strong>条件：query部分，基于这个条件搜索文档，并且基于BM25算法给文档打分，<strong>原始算分</strong>（query score)</p></li> <li><p><strong>过滤条件</strong>：filter部分，符合该条件的文档才会重新算分</p></li> <li><p>算分函数</p> <p>：符合filter条件的文档要根据这个函数做运算，得到的</p> <p>函数算分</p> <p>（function score），有四种函数</p> <ul><li>weight：函数结果是常量</li> <li>field_value_factor：以文档中的某个字段值作为函数结果</li> <li>random_score：以随机数作为函数结果</li> <li>script_score：自定义算分函数算法</li></ul></li> <li><p>运算模式</p> <p>：算分函数的结果、原始查询的相关性算分，两者之间的运算方式，包括：</p> <ul><li>multiply：相乘</li> <li>replace：用function score替换query score</li> <li>其它，例如：sum、avg、max、min</li></ul></li></ul> <p>function score的运行流程如下：</p> <ul><li>1）根据<strong>原始条件</strong>查询搜索文档，并且计算相关性算分，称为<strong>原始算分</strong>（query score）</li> <li>2）根据<strong>过滤条件</strong>，过滤文档</li> <li>3）符合<strong>过滤条件</strong>的文档，基于<strong>算分函数</strong>运算，得到<strong>函数算分</strong>（function score）</li> <li>4）将<strong>原始算分</strong>（query score）和<strong>函数算分</strong>（function score）基于<strong>运算模式</strong>做运算，得到最终结果，作为相关性算分。</li></ul> <p>因此，其中的关键点是：</p> <ul><li>过滤条件：决定哪些文档的算分被修改</li> <li>算分函数：决定函数算分的算法</li> <li>运算模式：决定最终算分结果</li></ul> <p>示例：</p> <p>需求：给“如家”这个品牌的酒店排名靠前一些</p> <p>翻译一下这个需求，转换为之前说的四个要点：</p> <ul><li>原始条件：不确定，可以任意变化</li> <li>过滤条件：brand = &quot;如家&quot;</li> <li>算分函数：可以简单粗暴，直接给固定的算分结果，weight</li> <li>运算模式：比如求和</li></ul> <p>因此最终的DSL语句如下：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;function_score&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;all&quot;</span><span class="token operator">:</span> <span class="token string">&quot;外滩&quot;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;functions&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span>
          <span class="token property">&quot;filter&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
              <span class="token property">&quot;brand&quot;</span><span class="token operator">:</span> <span class="token string">&quot;如家&quot;</span>
            <span class="token punctuation">}</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token property">&quot;weight&quot;</span><span class="token operator">:</span> <span class="token number">100</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
      <span class="token property">&quot;boost_mode&quot;</span><span class="token operator">:</span> <span class="token string">&quot;sum&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><p>result:</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549738.png" loading="lazy" class="lazy"></p> <p>function score query定义的三要素是什么？</p> <ul><li>过滤条件：哪些文档要加分</li> <li>算分函数：如何计算function score</li> <li>加权方式：function score 与 query score如何运算</li></ul> <h5 id="布尔查询"><a href="#布尔查询" class="header-anchor">#</a> 布尔查询</h5> <p>布尔查询是一个或多个查询子句的组合，每一个子句就是一个<strong>子查询</strong>。子查询的组合方式有：</p> <ul><li>must：必须匹配每个子查询，类似“与”</li> <li>should：选择性匹配子查询，类似“或”</li> <li>must_not：必须不匹配，<strong>不参与算分</strong>，类似“非”</li> <li>filter：必须匹配，<strong>不参与算分</strong></li></ul> <p>比如在搜索酒店时，除了关键字搜索外，我们还可能根据品牌、价格、城市等字段做过滤：</p> <p>每一个不同的字段，其查询的条件、方式都不一样，必须是多个不同的查询，而要组合这些查询，就必须用bool查询了。</p> <p>需要注意的是，搜索时，参与<strong>打分的字段越多，查询的性能也越差</strong>。因此这种多条件查询时，建议这样做：</p> <ul><li>搜索框的关键字搜索，是全文检索查询，使用must查询，参与算分</li> <li>其它过滤条件，采用filter查询。不参与算分</li></ul> <h6 id="基本语法-16"><a href="#基本语法-16" class="header-anchor">#</a> 基本语法</h6> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;bool&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;must&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span><span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token property">&quot;city&quot;</span><span class="token operator">:</span> <span class="token string">&quot;上海&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
      <span class="token property">&quot;should&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span><span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token property">&quot;brand&quot;</span><span class="token operator">:</span> <span class="token string">&quot;皇冠假日&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token punctuation">{</span><span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token property">&quot;brand&quot;</span><span class="token operator">:</span> <span class="token string">&quot;华美达&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
      <span class="token property">&quot;must_not&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span> <span class="token property">&quot;range&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">&quot;lte&quot;</span><span class="token operator">:</span> <span class="token number">500</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">}</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
      <span class="token property">&quot;filter&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span> <span class="token property">&quot;range&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token property">&quot;score&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">&quot;gte&quot;</span><span class="token operator">:</span> <span class="token number">45</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">}</span>
      <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><p>示例：</p> <p>需求：搜索名字包含“如家”，价格不高于400，在坐标31.21,121.5周围10km范围内的酒店。</p> <p>分析：</p> <ul><li>名称搜索，属于全文检索查询，应该参与算分。放到must中</li> <li>价格不高于400，用range查询，属于过滤条件，不参与算分。放到must_not中</li> <li>周围10km范围内，用geo_distance查询，属于过滤条件，不参与算分。放到filter中</li></ul> <p>result：</p> <p><img alt="" data-src="https://pic.yupi.icu/5563/202312241549934.png" loading="lazy" class="lazy"></p> <h4 id="搜索结果处理"><a href="#搜索结果处理" class="header-anchor">#</a> 搜索结果处理</h4> <h5 id="排序"><a href="#排序" class="header-anchor">#</a> 排序</h5> <p>地理坐标排序略有不同。</p> <p><strong>语法说明</strong>：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /indexName/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;sort&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;_geo_distance&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token property">&quot;FIELD&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;纬度，经度&quot;</span><span class="token punctuation">,</span> <span class="token comment">// 文档中geo_point类型的字段名、目标坐标点</span>
          <span class="token property">&quot;order&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;asc&quot;</span><span class="token punctuation">,</span> <span class="token comment">// 排序方式</span>
          <span class="token property">&quot;unit&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;km&quot;</span> <span class="token comment">// 排序的距离单位</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>这个查询的含义是：</p> <ul><li>指定一个坐标，作为目标点</li> <li>计算每一个文档中，指定字段（必须是geo_point类型）的坐标 到目标点的距离是多少</li> <li>根据距离排序</li></ul> <h5 id="分页"><a href="#分页" class="header-anchor">#</a> 分页</h5> <p>elasticsearch 默认情况下只返回top10的数据。而如果要查询更多数据就需要修改分页参数了。elasticsearch中通过修改from、size参数来控制要返回的分页结果：</p> <ul><li>from：从第几个文档开始</li> <li>size：总共查询几个文档</li></ul> <p>类似于mysql中的<code>limit ?, ?</code></p> <p>分页的基本语法如下：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;from&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token comment">// 分页开始的位置，默认为0</span>
  <span class="token property">&quot;size&quot;</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token comment">// 期望获取的文档总数</span>
  <span class="token property">&quot;sort&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span><span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;asc&quot;</span><span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>现在，我要查询990~1000的数据，查询逻辑要这么写：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;from&quot;</span><span class="token operator">:</span> <span class="token number">990</span><span class="token punctuation">,</span> <span class="token comment">// 分页开始的位置，默认为0</span>
  <span class="token property">&quot;size&quot;</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token comment">// 期望获取的文档总数</span>
  <span class="token property">&quot;sort&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span><span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;asc&quot;</span><span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>这里是查询990开始的数据，也就是 第990~第1000条 数据。</p> <p>不过，elasticsearch内部分页时，必须先查询 0~1000条，然后截取其中的990 ~ 1000的这10条：</p> <p>查询TOP1000，如果es是单点模式，这并无太大影响。</p> <p>但是elasticsearch将来一定是集群，例如我集群有5个节点，我要查询TOP1000的数据，并不是每个节点查询200条就可以了。</p> <p>因为节点A的TOP200，在另一个节点可能排到10000名以外了。</p> <p>因此要想获取整个集群的TOP1000，必须先查询出每个节点的TOP1000，汇总结果后，重新排名，重新截取TOP1000。</p> <p>那如果我要查询9900~10000的数据呢？是不是要先查询TOP10000呢？那每个节点都要查询10000条？汇总到内存中？</p> <p>当查询分页深度较大时，汇总数据过多，对内存和CPU会产生非常大的压力，因此elasticsearch会禁止from+ size 超过10000的请求。</p> <p>针对深度分页，ES提供了两种解决方案，<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html" target="_blank" rel="noopener noreferrer">官方文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>：</p> <ul><li>search after：分页时需要排序，原理是从上一次的排序值开始，查询下一页数据。官方推荐使用的方式。</li> <li>scroll：原理将排序后的文档id形成快照，保存在内存。官方已经不推荐使用。</li></ul> <h5 id="高亮"><a href="#高亮" class="header-anchor">#</a> 高亮</h5> <p>高亮显示的实现分为两步：</p> <ul><li>1）给文档中的所有关键字都添加一个标签，例如<code>&lt;em&gt;</code>标签</li> <li>2）页面给<code>&lt;em&gt;</code>标签编写CSS样式</li></ul> <p><strong>高亮的语法</strong>：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /hotel/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token string">&quot;TEXT&quot;</span> <span class="token comment">// 查询条件，高亮一定要使用全文检索查询</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;highlight&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;fields&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 指定要高亮的字段</span>
      <span class="token property">&quot;FIELD&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;pre_tags&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&lt;em&gt;&quot;</span><span class="token punctuation">,</span>  <span class="token comment">// 用来标记高亮字段的前置标签</span>
        <span class="token property">&quot;post_tags&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&lt;/em&gt;&quot;</span> <span class="token comment">// 用来标记高亮字段的后置标签</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><p><strong>注意：</strong></p> <ul><li>高亮是对关键字高亮，因此<strong>搜索条件必须带有关键字</strong>，而不能是范围这样的查询。</li> <li>默认情况下，<strong>高亮的字段，必须与搜索指定的字段一致</strong>，否则无法高亮</li> <li>如果要对非搜索字段高亮，则需要添加一个属性：required_field_match=false</li></ul></div> <footer class="page-edit" style="margin:0;"><div class="edit-link"><a href="https://github.com/liyupi/codefather/edit/master/知识碎片/ElasticSearch 基础概念与入门使用.md" target="_blank" rel="noopener noreferrer">完善页面</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">最近更新:</span> <span class="time">12/26/2023, 1:17:29 PM</span></div></footer> <!----></div> <div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:86vh"><div style="font-weight:bold;">ElasticSearch 基础概念与入门使用</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#前言" class="toc-sidebar-link">前言</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基础概念" class="toc-sidebar-link">基础概念</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#文档" class="toc-sidebar-link">文档</a></li><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#分词器" class="toc-sidebar-link">分词器</a></li><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#索引与映射" class="toc-sidebar-link">索引与映射</a></li><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#mysql-与-elasticsearch-一些概念的对比" class="toc-sidebar-link">mysql 与 elasticsearch 一些概念的对比</a></li></ul></li><li><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#安装" class="toc-sidebar-link">安装</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#安装中文分词器" class="toc-sidebar-link">安装中文分词器</a></li></ul></li><li><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#使用" class="toc-sidebar-link">使用</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#索引的增删改查" class="toc-sidebar-link">索引的增删改查</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#mapping-映射属性" class="toc-sidebar-link">mapping 映射属性</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#创建索引库和映射" class="toc-sidebar-link">创建索引库和映射</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#示例-以上面的数据为例-我们所有的操作都在-kibana-的中-dev-tools-中完成" class="toc-sidebar-link">示例（以上面的数据为例，我们所有的操作都在 Kibana 的中 dev tools 中完成）</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#查询索引库" class="toc-sidebar-link">查询索引库</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-2" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#修改索引库" class="toc-sidebar-link">修改索引库</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-3" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#删除索引库" class="toc-sidebar-link">删除索引库</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-4" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#文档的增删改查" class="toc-sidebar-link">文档的增删改查</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#新增文档" class="toc-sidebar-link">新增文档</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-5" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#查询文档" class="toc-sidebar-link">查询文档</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-6" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#删除文档" class="toc-sidebar-link">删除文档</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-7" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#修改文档" class="toc-sidebar-link">修改文档</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#全量修改" class="toc-sidebar-link">全量修改</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-8" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#增量修改" class="toc-sidebar-link">增量修改</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-9" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#利用-restapi-在-java-中使用-elasticsearch" class="toc-sidebar-link">利用 RestAPI 在 Java 中使用 ElasticSearch</a></li><li class="toc-sidebar-sub-header"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#如何搜索-dsl查询文档" class="toc-sidebar-link">如何搜索 ==&gt; DSL查询文档</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#数组准备" class="toc-sidebar-link">数组准备</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#dsl-查询分类" class="toc-sidebar-link">DSL 查询分类</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#查询基本语法" class="toc-sidebar-link">查询基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#全文检索查询" class="toc-sidebar-link">全文检索查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-10" class="toc-sidebar-link">基本语法</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本格式" class="toc-sidebar-link">基本格式：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#精确查询" class="toc-sidebar-link">精确查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#term-查询" class="toc-sidebar-link">Term 查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-11" class="toc-sidebar-link">基本语法</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#range-查询" class="toc-sidebar-link">range 查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-12" class="toc-sidebar-link">基本语法</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#" class="toc-sidebar-link"></a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#地理坐标查询" class="toc-sidebar-link">地理坐标查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#矩形范围查询" class="toc-sidebar-link">矩形范围查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-13" class="toc-sidebar-link">基本语法</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#附近查询" class="toc-sidebar-link">附近查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-14" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#复合查询" class="toc-sidebar-link">复合查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#算分函数查询" class="toc-sidebar-link">算分函数查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-15" class="toc-sidebar-link">基本语法：</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#布尔查询" class="toc-sidebar-link">布尔查询</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-6"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#基本语法-16" class="toc-sidebar-link">基本语法</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-4"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#搜索结果处理" class="toc-sidebar-link">搜索结果处理</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#排序" class="toc-sidebar-link">排序</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#分页" class="toc-sidebar-link">分页</a></li><li class="toc-sidebar-sub-header toc-sidebar-depth-5"><a href="/elasticsearch-%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%85%A5%E9%97%A8%E4%BD%BF%E7%94%A8/#高亮" class="toc-sidebar-link">高亮</a></li></ul></li></ul></div></div></div></div></div>  <main class="footer"> <div class="copy-right"><span class="name"> 编程导航   |     </span> <a target="_blank" rel="noreferrer">
          
        </a></div></main></main> <aside class="page-sidebar"> <div class="page-side-toolbar"></div>  </aside></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.12ab4756.js" defer></script><script src="/assets/js/2.fd06b53e.js" defer></script><script src="/assets/js/51.bed7cf61.js" defer></script>
  </body>
</html>
